laravel-5.3

How can I display modal in modal on vue component?

99封情书 提交于 2019-11-28 14:47:33
My view blade like this : <a href="javascript:" class="btn btn-block btn-success" @click="modalShow('modal-data')"> Click here </a> <data-modal id="modal-data"></data-modal> If the button clicked, it will call dataModal component (In the form of modal) dataModal component like this : <template> <div class="modal" tabindex="-1" role="dialog"> <div class="modal-dialog" role="document"> <!-- modal content data --> <div class="modal-content modal-content-data"> <form id="form"> <div class="modal-body"> ... </div> ... <button type="submit" class="btn btn-success" @click="add"> Save </button> ... <

Laravel 5.3 - How to add Sessions to `API` without CSRF?

浪尽此生 提交于 2019-11-28 14:29:32
Im trying to build an api , and for some reason I need sessions. But if I include web middleware I get CSRF errors, and if I dont I cant have session started. How to solve this? go to app/Http/Kernel.php and add your own name like 'sessions' to the $middlewareGroups. It should contain \Illuminate\Session\Middleware\StartSession::class, Assign 'sessions' to those routes you want. protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate

Laravel 5.3 multiple file uploads

匆匆过客 提交于 2019-11-28 11:59:28
How can I upload multiple files in Laravel 5.3 . If I try it with 1 image it works but multiple images are not uploaded. This is my code: if($request->hasFile('attachment')) { foreach ($request->allFiles('attachments') as $file) { $file->store('users/' . $user->id . '/messages'); } } Jamie It works now like this: $files = $request->file('attachment'); if($request->hasFile('attachment')) { foreach ($files as $file) { $file->store('users/' . $this->user->id . '/messages'); } } I had to append [] after the value of the name attribute, so: <input type="file" name="attachment[]" multiple> Mayank

Laravel 5.3 Login redirect to different pages for multiple users

ε祈祈猫儿з 提交于 2019-11-28 11:28:35
I have Laravel 5.3 with three different types of users. I want them to be redirected to different dashboard pages after logging in. For example: user -> login -> user-dashboard admin -> login -> admin-dashboard I have created a middleware called CheckRole : public function handle($request, Closure $next) { if($request->user() === null) { return response("Insufficient Permissions" , 401); } $actions = $request->route()->getAction(); $roles = isset($actions['roles']) ? $actions['roles'] : null; if($request->user()->hasAnyRole($roles) || !$roles) { return $next($request); } return response(

How to create query with twice a connection to a table in Laravel 5.3?

自古美人都是妖i 提交于 2019-11-28 09:33:40
问题 I need get two city names with one query: For example: City table: +---------+----------+ | Pana | Name | +---------+----------+ | THR | Tehran | | LON | London | +---------+----------+ In Model: from_city is THR and to_city is LON public function scopePrintQuery($query, $id) { $join = $query -> join('cities', 'cities.pana', 'flights.from_city') -> join('cities', 'cities.pana', 'flights.to_city') -> where('flights.id', $id) ->get([ 'flights.*', 'cities.name as from_city' ??? for to_city? ]);

How to remove an item from session array in laravel

ⅰ亾dé卋堺 提交于 2019-11-28 09:19:02
问题 Here is the problem I have a session session('products') this is actually an array that contains id session('products') array:4 [▼ 0 => "1" 1 => "2" 2 => "4" 3 => "1" ] Now I want to delete lets say 4 How do I do that? I tried method session()->pull($product, 'products'); But it didn't work! Other solution session()->forget('products', $product); it also didn't work 回答1: You AFAIR have to firstly retrieve whole array, edit it and then set it again. If you want to delete by product ID, which

Laravel 5.3 Passing AuthorizationException a message when a Policy fails

狂风中的少年 提交于 2019-11-28 09:11:51
问题 I'm trying to find a clean way to override the AuthorizationException to take a dynamic string that can be passed back when a policy fails. Things I know I can do are: 1) Wrap the policy in the controller with a try-catch, then rethrow a custom exception that takes a specific string, which seems a bit verbose 2) abort(403, '...') in the policy prior to returning, which seems a bit hacky since policies are already doing the work and then in /Exceptions/Handler::render I can send back the

Call to undefined method Illuminate\\Database\\Query\\Builder::lists() when seeding after updating to Laravel 5.3

不问归期 提交于 2019-11-28 08:54:22
I'm updating to laravel 5.3, and I get this message: [2016-08-23 23:12:39] local.ERROR: BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::lists() in /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2431 Stack trace: #0 [internal function]: Illuminate\Database\Query\Builder->__call('lists', Array) #1 /home/vagrant/Code/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1423): call_user_func_array(Array, Array) #2 /home/vagrant/Code/vendor/cviebrock/eloquent-sluggable/src/SluggableTrait.php(254): Illuminate

Laravel Eloquent Union query

旧巷老猫 提交于 2019-11-28 08:06:10
问题 So I have the following query: $a = Model::where('code', '=', $code) ->where('col_a', '=' , 1) ->orderBy(DB::raw('FIELD(layout, "normal", "split", "flip", "double-faced", "") ASC, layout')) $b = Model::where('code', '=', $code) ->where('col_b', '=' , 1) ->orderBy(DB::raw('FIELD(layout, "normal", "split", "flip", "double-faced", "") ASC, layout')) $a->union($b)->get(); No sorting is happening when I 'orderBy()' first and then union. When I do query '$a' or '$b' individually the 'orderBy()'

Laravel - link to a file saved in storage folder

China☆狼群 提交于 2019-11-28 05:36:06
问题 When we do something like this: Storage::disk('local')->put('file.txt', 'Contents'); How do you make a link to that file in a view? Something like this: <a href="path_to_file.txt">Download File</a> there are so many things in documentation and yet not even one example how to create a link to that file 回答1: UPDATE : According to laravel docs, You can get the URL to the file like this: use Illuminate\Support\Facades\Storage; $url = Storage::url('file1.jpg'); Remember, if you are using the local