in laravel i'm trying to check user active
column and if its 0
then must be show simple view as your account is disable
, after implementing below codes i get this error:
my middleware:
class CheckUserActive
{
public function handle($request, Closure $next)
{
if (auth()->check()) {
if (auth()->user()->active == 0) {
auth()->logout();
$message = 'your account is disable';
return view('layouts.frontend.pages.user-messages', compact('message'));
}
}
return $next($request);
}
}
kernel.php
:
...
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\CheckUserActive::class,
],
'api' => [
'throttle:60,1',
'bindings',
],
];
...
user-messages.blade.php
:
@extends('layouts.frontend.main')
@section('content')
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-body">
<p style="text-align: center;">
{!! $message !!}
</p>
</div>
</div>
</div>
</div>
</div>
</div>
@endsection
Views may also be returned using the View facade: use Illuminate\Support\Facades\View; return View::make('greeting', ['name' => 'James']); As you can see, the first argument passed to the view helper corresponds to the name of the view file in the resources/views directory.
Loading a view in the controller is easy. You just need to add `view('viewname')` method while returning from the controller method. `view()` is a global helper in Laravel. In this method, you just need to pass the name of the view.
Laravel Middleware acts as a bridge between a request and a reaction. It is a type of sifting component. Laravel incorporates a middleware that confirms whether or not the client of the application is verified. If the client is confirmed, it diverts to the home page otherwise, it diverts to the login page.
based on the documentation, you can access view using
response()->view('custom');
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