vendredi 26 mai 2017

Laravel 5.4 - Use Controller outside of a route

I haven't been able to use controllers outside of routes.

I want to be able to access a column in a row, in my users table. I want to get the users ID and assign it to a variable. But I don't want to use a route because this isn't for a page; it's for my master layout file.

I have a column called "admin". If this is equal to 1, I want to use @if in my menu bar to display a link to the admin control panel. But to get the admin column I need to be able to access the users table.

I've tried doing this by using jQuery to assign the user ID to a variable on page load:

$(window).load(function(){ 

    get('userController@index');

    $userID = ;
    console.log($userID);

})

I also tried

$(window).load(function(){ 

    Route::get('userController@index');

    $userID = ;
    console.log($userID);

})

Essentially, I don't know how to access Models or Controllers without routes, eg:

Route::get('/home', 'HomeController@index')->name('home');

The Laravel error I get is

Undefined variable: user

I know that I'm not accessing the admin column here, I know how to do that once I can access the user table.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rHIZ3o
via IFTTT

Aucun commentaire:

Enregistrer un commentaire