Эй, ребята, я недавно работаю над Laravel. Я столкнулся с проблемой проверки подлинности.
Это то, что всякий раз, когда я пытаюсь аутентифицировать пользователя и перенаправляю его на представление конкретного контроллера, он отлично работает, но затем, когда я пытаюсь открыть другое представление, аутентификация пользователя не работает (пользователь выходит из системы). в основном проблема заключается в том, что у меня есть два контроллера, поэтому, если я перенаправляю от аутентификации к любому из них, у другого нет пользователя.
Я надеюсь, что я объяснил свою проблему ясноLaravel Authentication не работает несколько контроллеров
Список Маршрут: Результат Route List
Основные маршруты страницы являются те, что я работаю с ... другими просто болван, как сейчас
Это мой класс аутентификации
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Auth\Guard;
class Authenticate
{
/**
* The Guard implementation.
*
* @var Guard
*/
protected $auth;
public function __construct(Guard $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('/');
}
}
return $next($request);
}
}
Это контроллер Index
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class IndexPageController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$user = Auth::user()->firstOrFail();
return view('index')
->with(compact('user'));
//
}
Это UserProfileController
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class UserProfileController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$user = Auth::user()->firstOrFail();
return view('profile.index')
->with(compact('user'));
//
}
Маршруты
<?php
use Illuminate\Support\Facades\Mail;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*Welcome Page routes */
Route::get('/' , function(){
return view('auth.login');
});
Route::get('user/logout' , function(){
Auth::logout();
return redirect('/');
});
Route::post('user/do-login' , 'Auth\[email protected]');
Route::get('user/create' , 'Auth\[email protected]');
/*---------------------------*/
/*Welcome Page AJAX routes*/
Route::get('/checkAvailibility' , '[email protected]');
/*---------------------------*/
/*Images Routes*/
Route::post('image/do-upload' ,'[email protected]');
Route::post('gallery/save' , '[email protected]');
Route::get('gallery/list' , '[email protected]');
Route::get('gallery/view/{id}' , '[email protected]');
Route::get('gallery/delete/{id}' , '[email protected]');
/*---------------------------*/
/*Event Routes */
Route::post('create/Image-Upload' , '[email protected]');
Route::post('create' , '[email protected]');
Route::get('create/event-image' , '[email protected]');
Route::post('create/event-image' , 'CreateEventForm[email protected]');
Route::get('create' , '[email protected]');
Route::get('event/{id}' , [ 'as' => 'event_list' , 'uses' => '[email protected]']);
/*---------------------------*/
/*-------------- Main Page Routes -------------------*/
Route::get('event/{id}' , [ 'as' => 'event_list' , 'uses' => '[email protected]']);
Route::get('index' ,[ 'as' => 'index' , 'uses' => '[email protected]']);
/*-------------- END -------------------*/
/*-------------- Main Page Routes -------------------*/
Route::get('profile' , '[email protected]');
Route::get('profile/{id}' , '[email protected]');
/*-------------- END -------------------*/
Route::get('/email', function() {
$data = array(
'name' => "Learning Laravel",
);
Mail::send('emails.test', $data, function ($message) {
$message->from('[email protected]', 'Learning Laravel');
$message->to('[email protected]')->subject('Learning Laravel test email');
});
return "Your email has been sent successfully";
});
Какая версия Laravel? –
Laravel version 5.1 –
Можете ли вы обновить вопрос своими методами управления? –