laravel-5.4

Laravel login as another user

浪子不回头ぞ 提交于 2019-11-30 23:49:21
I am currently developing a laravel app where there are 3 user_roles Superadmin Admin Normal So each role can access the roles below him. e.g Superadmins can access admins and normal users account. How do I allow a authenticated superadmin user to log in as an admin or normal user with a click of a button? USER_ROLES TABLE id name 1 superadmin 2 admin 3 normal ---------------------------- USERS TABLE id first_name last_name user_role_id password 1 john doe 1 ******* 2 jane doe 2 ******* 3 cassie snow 3 ******* 4 sansa stark 3 ******* Reading the comments I think you want to do the following:

Laravel Passport token lifetime

*爱你&永不变心* 提交于 2019-11-30 23:22:43
问题 I don't get what I'm doing wrong. I can't set token expiration time. <?php namespace App\Providers; class AuthServiceProvider extends ServiceProvider { public function boot() { $this->registerPolicies(); Passport::tokensExpireIn(Carbon::now()->addDays(1)); Passport::refreshTokensExpireIn(Carbon::now()->addDays(30)); } } BUT when I call $user->createToken() , for example like this: <?php // as a demo namespace App\Http\Middleware; class ParseSpecialToken { public function handle($request,

Laravel Route issues with Route order in web.php

只愿长相守 提交于 2019-11-30 22:08:08
I have problem with routes in Laravel, I'm following one tutorial and we have this routes listed in web.php file Route::get('/home', 'HomeController@index')->name('home'); Route::get('/blog', 'BlogController@index')->name('blog'); Route::get('/blog/create', 'BlogController@create'); Route::post('/blog/store', 'BlogController@store'); Route::get('/blog/{id}', 'BlogController@show'); Route::get('/blog/{id}/edit', 'BlogController@edit'); Route::patch('/blog/{id}', 'BlogController@update'); Route::delete('/blog/{id}', 'BlogController@destroy'); Route::get('/blog/bin', 'BlogController@bin');

Laravel login as another user

坚强是说给别人听的谎言 提交于 2019-11-30 18:51:31
问题 I am currently developing a laravel app where there are 3 user_roles Superadmin Admin Normal So each role can access the roles below him. e.g Superadmins can access admins and normal users account. How do I allow a authenticated superadmin user to log in as an admin or normal user with a click of a button? USER_ROLES TABLE id name 1 superadmin 2 admin 3 normal ---------------------------- USERS TABLE id first_name last_name user_role_id password 1 john doe 1 ******* 2 jane doe 2 ******* 3

How to redirect to a route from a controller method

允我心安 提交于 2019-11-30 18:29:05
问题 I have defined a method in my controller, where inputs are first retrieved, and if the email field is present in my database, I would like to return a view. However, if the email field isn't present, I would like to redirect to another route. I would also like to pass in the inputs to that route as well. To better understand what I mean, my code is as follows for my controller: public function index(Request $request) { $credentials = $request->all(); if (\App\User::where('email','=',

Laravel : Many to many insertion

本小妞迷上赌 提交于 2019-11-30 17:20:11
I have two models, User and Team The relationship between them is ManyToMany : In User : public function teamMembers(){ return $this->belongsToMany('App\Team')->withPivot('id');; } And in Team : public function teamMembers(){ return $this->belongsToMany('App\User')->withPivot('id');; } Now i want to add users to a specific team. So the pivot table name is team_user . Now the data i want to insert to pivot table is : array:4 [▼ "_token" => "mlwoAgCQYals1N1s2lNa4U5OTgtMNHh9LUhNGrWh" "team_id" => "1" "members_id" => array:3 [▼ 0 => "2" 1 => "3" 2 => "4" ] "status" => "1" ] What i am doing in my

Two different models for authentication in laravel 5.4

Deadly 提交于 2019-11-30 15:53:05
Suppose I have two different models and tables named user and company . As you know laravel uses User model to manage Authentication. but beacause I have two different model I want can manage them separately. I'm using laravel 5.4 and I do not know how can do that. If you are talking about multiple authentication system, then you have to create multiple guards to achieve that. There is nice answer to the same question. Can anyone explain Laravel 5.2 Multi Auth with example It's on Laravel 5.2, but it can be easily implemented on Laravel 5.4. Create a model App\Company which extends

Laravel 5.4 - How to set PDO Fetch Mode?

家住魔仙堡 提交于 2019-11-30 15:13:57
问题 The ability to customize the fetch mode was removed from L5.4 and is defaulted to PDO::FETCH_OBJ. The upgrade guide states that you can override this by using an event listener: Event::listen(StatementPrepared::class, function ($event) { $event->statement->setFetchMode(...); }); I can't for the life of me understand how to implement this: 1) Where should I place the code? Should I register it with the EventServiceProvider ? 2) When does the StatementPrepared event fire? (I only need to change

Laravel 5.4 - How to set PDO Fetch Mode?

佐手、 提交于 2019-11-30 14:02:56
The ability to customize the fetch mode was removed from L5.4 and is defaulted to PDO::FETCH_OBJ. The upgrade guide states that you can override this by using an event listener: Event::listen(StatementPrepared::class, function ($event) { $event->statement->setFetchMode(...); }); I can't for the life of me understand how to implement this: 1) Where should I place the code? Should I register it with the EventServiceProvider ? 2) When does the StatementPrepared event fire? (I only need to change the Fetch Mode for specific repository functions, not on a global scale). 3) Does the FetchMode revert

Laravel 5.4 - How to override route defined in a package?

江枫思渺然 提交于 2019-11-30 13:59:51
I have created a package in Laravel 5.4 that sets up a basic backoffice. This package contains several routes that are using controllers from within the package. What I want to be able to do is to override the package defined routes in my application in order to plug custom controllers. For example, if I have a route Route::get('login', [ 'as' => 'admin.login', 'uses' => 'Auth\LoginController@showLoginForm' ]); defined in my package that will use the Vendor\Package\Controllers\Auth\LoginController I want to defined a route for my application that will override that one and use the App