laravel-5.3

How can I do Authorization Policies in Laravel 5.3?

一世执手 提交于 2020-01-07 03:11:13
问题 I read here : https://laravel.com/docs/5.3/authorization#writing-policies And I tried to like this My FavoritePolicy is like this : <?php namespace App\Policies; use App\User; use App\Models\Favorite; use Illuminate\Auth\Access\HandlesAuthorization; class FavoritePolicy { use HandlesAuthorization; public function view(User $user, Favorite $favorite) { return $user->id === $favorite->user_id; } } My FavoriteController is like this : <?php use App\Models\Favorite; ... class FavoriteController

Blade if condition in controller function

梦想与她 提交于 2020-01-07 02:38:08
问题 Is it possible to use blade @if conditions in functions of controller. This is my function of PublicController public function tourBanner($country){ @if( $country == 'country1') background-image:url({{ asset('images/inside8.jpg') }}); @elseif ( $country == 'country2') background-image:url({{ asset('images/inside7.jpg') }}); @elseif ( $country == 'country3') background-image:url({{ asset('images/inside5.jpg') }}); @elseif ( $country == 'country4') background-image:url({{ asset('images/inside6

Ways to prevent TokenMismatch Exception using AJAX in laravel

南笙酒味 提交于 2020-01-05 07:33:39
问题 I have analyze that ratio of getting Token Mismatch Error is very high. And this error getting because of some of the silly mistakes. There are many reasons developers are doing mistakes. Here are some of the examples. Not sending _token on header. Not sending _token on data when using ajax. Not Permission on Storage Path. Invalid Session Storage path. And there many other reasons, feel free to edit this question for more more ways to prevent this type of error. 回答1: Possible Change - 1 Setup

Laravel scheduler - Run specific days of month at specific time

痞子三分冷 提交于 2020-01-05 05:59:29
问题 I want to run a task at specific days of month in specific time. Now i use this code to run the task on 1st and 15th day of the month. $schedule->command('payments:create')->daily()->when(function () { $days = [1,15]; $today = Carbon::today(); return in_array($today->day, $days); }); Is there any way to set this task to run on these days at specific time? 回答1: You can achieve it in many ways, following two liner : $schedule->command('payments:create')->monthlyOn(1, '15:00'); $schedule-

Laravel's Mail notification won't send, but Laravel's Mail::Raw will

▼魔方 西西 提交于 2020-01-05 04:56:11
问题 I have configured my SMTP server correctly in Laravel's env file, and can successfully send an email using Mail::raw e.g. Mail::raw("This is a test message", function ($message) { $message->from(env("MAIL_ORDER_ADDRESS"), 'Orders'); $message->to('user@example.com'); $message->subject('Test Message'); }); However, when I use a laravel 5.3 mail notification, no email is received (nor is an error generated). I have tested the same notification code locally using mail trap and the notifications

Vue SPA url not working with history mode enabled

狂风中的少年 提交于 2020-01-04 19:47:34
问题 I am creating a SPA using Vue js and it kind of works but I have one problem. With history mode enabled on Vue I can enter urls and go to that page using the Vue Router but when I try to login I get the literal page html. I know I can do something like auth\{vue?} but I would prefer if i didn't have to do that. I want to be able to always keep the url with no prefixes unless it is to an API request. So for example: I have the root view: Route::get('/{vue?}', function () { return view('layouts

Laravel Delete/Forget Cookie not working

风格不统一 提交于 2020-01-04 04:37:09
问题 How do you a delete cookies in Laravel. This is not working: public function logout(Request $request) { $this->guard()->logout(); $request->session()->flush(); $request->session()->regenerate(); Cookie::queue(Cookie::forget('cavpad')); Cookie::queue(Cookie::forget('cavuser')); return redirect('/'); } This works, but seems the wrong way to do it: Cookie::queue(Cookie::make('cavpad', '', 0, null, env('APP_DOMAIN'))); Cookie::queue(Cookie::make('cavuser', '', 0, null, env('APP_DOMAIN'))); Why

laravel 5.4: sending email from localhost not working

可紊 提交于 2020-01-03 13:09:49
问题 I want to sent emails from my localhost with laravel 5.4. It is showing me the following error: screenshot of the error This is my .env file MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=myemail@gmail.com MAIL_PASSWORD=mypassword MAIL_ENCRYPTION=tfl This is my mail.php file <?php return [ /* |-------------------------------------------------------------------------- | Mail Driver |-------------------------------------------------------------------------- | | Laravel

Using session in custom middleware in laravel

。_饼干妹妹 提交于 2020-01-03 04:48:09
问题 I've simple middleware which checks if there is a key in user session. <?php namespace App\Http\Middleware; use Closure; class CustomAuth { public function handle($request, Closure $next) { if($request->session()->has('uid')){ return $next($request); } else{ return view('unauth'); } } } The problem is that I always get "Session store not set on request." error. Here is my route: Route::get('home', function () { return view('home'); })->middleware('web', 'CustomAuth'); I've added the

Checking if User is activated before sending Password Reset email using Forgot Password

你。 提交于 2020-01-02 05:12:05
问题 I'm creating a small app using Laravel 5.3 . I've applied user activation (via email confirmation) on Laravel's default Auth . But i couldn't find a way to stop sending password reset link if account/user not activated by verifying email address. Currently if a user creates an account and doesn't verify the email address he/she can login using Password Reset link. this what i've in user table public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id')