我正在使用laravel用于我的web应用程序,在登录时我要求输入用户名,密码,我想检查登录用户的电子邮件是否已经过验证.如果验证状态为0,我想使用名为中间件的verifiedemail将错误消息发送到登录页面.
route.php
Route::group(['middleware' => 'auth', 'superadmin'], function () {
Route::resource('/users', 'UserController');
});
Route::get('/', function () {
if (Auth::guest())
return view('/auth/login');
else
return redirect('/tests');
});
Route::resource('/tests', 'TestController');
Route::get('/sites', 'SiteController@index');
Auth::routes();
Route::get('/home', 'HomeController@index');
Run Code Online (Sandbox Code Playgroud)
Redirectedifauthenticated.php <---中间件文件
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/home');
}
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
verifiedemail.php <---中间件文件
public function handle($request, Closure $next)
{
if ( Auth::check() && Auth::user()->isVerifiedEmail() )
{
return redirect('/login');
}
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
kernel.php
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class, …Run Code Online (Sandbox Code Playgroud) 在我的laravel项目中,当我单击注销时,如果会话超时,则会显示并显示令牌未命中错误。但是我希望它进入登录页面。如何解决此问题。
在其他页面中,当会话超时时,它会进入登录页面,我也希望注销。
在我的网络中,所有其他页面均在以下身份验证中间件下,这可能是其他页面正常工作的原因。
Route::group(['middleware' => ['auth', 'changepassword']], function ()
{ }
Run Code Online (Sandbox Code Playgroud) 在我的 laravel 项目中,我需要一次添加多条记录,我还想插入created_at和updated_at,就像在save()中自动工作一样。但在插入方法中不起作用。
for($i=0; $i<count($req->location_id); $i++)
{
$asset_arr[$i]['property_id'] = $this->id;
$asset_arr[$i]['location_id'] = $req->location_id[$i];
$asset_arr[$i]['model_id'] = $req->model_id[$i];
$asset_arr[$i]['appliance_owner'] = $req->appliance_owner[$i];
$asset_arr[$i]['current'] = $req->current[$i];
if($req->installdate[$i]!=''){
$asset_arr[$i]['installdate'] = date('Y-m-d',strtotime($req->installdate[$i]));
}
$asset_arr[$i]['comment'] = $req->comment[$i];
}
if(!empty($asset_arr)){
Asset::insert($asset_arr);
}
Run Code Online (Sandbox Code Playgroud) 想要使用laravel更新数据.我在模型中创建了一个函数,并在控制器内部使用该方法,但在调用方法时,它使用新的id.function插入数据,如下所示.
public function edit_client($req,$id) {
$client = new client();
$client->find($id);
$client->name = $req->name;
$client->address = $req->address;
$client->email = $req->email;
$client->phone = $req->phone;
$client->gender = $req->gender;
$client->department = $req->department;
$client->update();}
Run Code Online (Sandbox Code Playgroud) 在我的laravel项目中,我创建了一个控制器,用于删除所有刀片中的项目调用相同的控制器.通过动态id和模型名称.但是找不到类的错误.例如:未找到"用户"类.
如何添加用户; 我的控制器中的代码动态.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AjaxController extends Controller
{
public function deleteItem(Request $req)
{
use $req['model'];
$id = $req['id'];
$model_name = $req['model'];
$mdoel_name = $model_name::find($id);
$mdoel_name->delete();
sactivity('delete')->performedOn($mdoel_name)->log('');
return "success";
}
}
Run Code Online (Sandbox Code Playgroud)