laravel-5.5

How can I configure an SCP/SFTP file storage?

跟風遠走 提交于 2019-12-05 16:10:26
My Laravel application should copy files to another remote host. The remote host is accessible only via SCP with a private key. I would like to configure a new file storage ( similarly as FTP ), but I have found no information, how to define an SCP driver. You'll need to install the SFTP driver for Flysystem, the library Laravel uses for its filesystem services: composer require league/flysystem-sftp Here's an example configuration that you can tweak. Add to the disks array in config/filesystems.php : 'sftp' => [ 'driver' => 'sftp', 'host' => 'example.com', 'port' => 21, 'username' =>

Soft deleting in pivot with sync method laravel

Deadly 提交于 2019-12-05 15:09:34
I want sync some relation in User's Table and I don't want to Laravel delete the row, I want make some updates on that row (Like fill the deleted_at), I searched so far and only solution i found is that to override sync method. So how i can override the sync method to update the row? Or whats another solution for this problem? EDITED: I know the problem is with detach method, If i could override the detach It will be solved! Thanks I think you were looking for this method. $user->your_relation()->updateExistingPivot($userid, ['deleted_at' => $date]); 来源: https://stackoverflow.com/questions

Laravel optional prefix routes with regexp

喜欢而已 提交于 2019-12-05 14:36:46
Is there a way to create routes with prefixes so I can have routes like this /articles.html -> goes to listing Controller in default language /en/articles.html -> goes to the same controller /fr/articles.html -> goes to the same controller My current problem is that by doing: Route::group(['prefix=>'/{$lang?}/',function(){}); a route like this: /authors/author-100.html will match a prefix 'authors` , and for sure there is no language called "authors". I use laravel 5.5 This should be sufficient using the where Regex match on the optional route parameter: Route::get('/{lang?}, 'SameController

How to edit the view of “The page has expired due to inactivity” in Laravel 5.5

情到浓时终转凉″ 提交于 2019-12-05 11:33:07
In Laravel 5.5, When you are using CSRF protection (by default) and you send a post request after long inactivity you'll get this error page (Screenshot). I'm ok with this error however, I need to change the view/text of this error to match my application style and my language for sure. Any Ideas in how to edit this view? Amade You can override the default view by placing a 419.blade.php file in the resources/views/errors folder. If you're using an editor with global search capabilities, you can search for the error message inside your project. For example, in Visual Studio Code you can press

post request using axios on Laravel 5.5

大兔子大兔子 提交于 2019-12-05 08:51:42
i'm trying to make some requests using axios and the last Laravel version 5.5 after configure the X-CSRF fields and all my code is simple : axios.post('/post-contact',{name:'Kamal Abounaim'}) .then((response)=>{ console.log(response) }).catch((error)=>{ console.log(error.response.data) }) but i get this error : 419 (unknown status) what the problem supposed to be Thanks for answering This is happening because of the csrf-token. Just add meta tag with the csrf-token in the <head> and add that token to axios header like so. // in the <head> <meta name="csrf-token" content="{{ csrf_token() }}">

Create dynamic Laravel accessor

流过昼夜 提交于 2019-12-05 08:28:10
I have a Product model and also an Attribute model. The relationship between Product and Attribute is many to many. On my Product model I am trying to create a dynamic accessor. I am familiar with Laravel's accessors and mutators feature as documented here . The problem I am having is that I do not want to create an accessor every time I create a product attribute. For example, A product may have a color attribute which could be setup like so: /** * Get the product's color. * * @param string $value * @return string */ public function getColorAttribute($value) { foreach ($this-

In Laravel 5.5, how to get the Job ID after we dispatch a job to the job queue?

亡梦爱人 提交于 2019-12-05 07:43:42
Until Laravel 5.4, the dispatch() method returned the queue job id. $job = (new JobClass())->onQueue('queuename'); $jobId = dispatch($job); dd($jobId); // prints the job id In 5.5, it returns a PendingDispatch object, which does not seem to have a method to retrieve the job id. I've already tried with dispatch_now() , but it executes the job immediately and synchronously, while I want it to be executed in the background. After opening an issue at Laravel github, the solution was to use: app(\Illuminate\Contracts\Bus\Dispatcher::class)->dispatch($job) instead of dispatch($job) You might also

How to take all the words in one normal array from the database in the Laravel framework with a minimum waste of time?

北城余情 提交于 2019-12-05 03:20:53
问题 I want to take all the words from the database into default array . I have more than 50,000 words in the database, and most likely this number is up to a million. Therefore, I want this operation did not take much time. I tried such ways in which not a word is put into the usual array. That is, the words are passed to the associative array: $words = DB::table('words')->pluck('word'); dump($words); Result: Collection {#197 ▼ #items: array:12 [▼ 0 => "тоҷик" 1 => "ӯзбек" 2 => "қирғиз" 3 =>

laravel APi resource Call to undefined method Illuminate\\Database\\Query\\Builder::mapInto()

北战南征 提交于 2019-12-04 23:30:20
i have Post and User model with one to one relation and it works good: //User.php public function post(){ return $this->hasOne(Post::class); } // Post.php public function user() { return $this->belongsTo(User::class); } now i create API resources: php artisan make:resource Post php artisan make:resource User I need to return all post with an api call then i set my route: //web.php: /resource/posts Route::get('/resource/posts', function () { return PostResource::collection(Post::all()); }); this is my Posts resource class: <?php namespace App\Http\Resources; use Illuminate\Http\Resources\Json

How to get current user in Laravel API using Passport?

你离开我真会死。 提交于 2019-12-04 22:56:53
问题 I am using passport package for Laravel API Authentication. When I post data I get error: 401 Unauthorized","error":{"error":"Unauthenticated."}. I use Auth::user()->id; to get current user id. How to solve this error? 回答1: This code helped me: auth()->guard('api')->user() 回答2: The simplest format is auth('api')->user(); 回答3: When you use Auth::user()->id in your function's body. You have not logged in before. Please call login api first to get token then set it to the next API call. 来源: