I am new to Laravel 5 and trying to understand its Auth
process. I want to prevent user to reach some of my pages unless the user is not logged in. Trying to make it with Route:filter
but it does not work. What i have done wrong ?
Route::filter('/pages/mainpage', function() { if(!Auth::check()) { return Redirect::action('PagesController@index'); } });
In other words, Auth::check() calls Auth::user() , gets the result from it, and then checks to see if the user exists. The main difference is that it checks if the user is null for you so that you get a boolean value. As you can see, it calls the user() method, checks if it's null, and then returns a boolean value.
The attempt method accepts an array of key / value pairs as its first argument. The password value will be hashed. The other values in the array will be used to find the user in your database table. So, in the example above, the user will be retrieved by the value of the email column.
How do I enable authentication in Laravel? You need to Install the laravel/ui Composer bundle and run php artisan ui vue –auth in a new Laravel application. After migrating your database, open http://your-app.test/register or any other URL that's assigned to your application on your browser.
You should use the auth
middleware. In your route just add it like this:
Route::get('pages/mainpage', ['middleware' => 'auth', 'uses' => 'FooController@index']);
Or in your controllers constructor:
public function __construct(){ $this->middleware('auth'); }
use
Auth::check()
more here https://laravel.com/docs/5.2/authentication#authenticating-users in Determining If The Current User Is Authenticated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With