laravel-5.5

Laravel Broadcast - Combining multiple middleware (web, auth:api)

末鹿安然 提交于 2019-12-08 01:45:06
问题 I am using Laravel Event Broadcast and Pusher to utilize websockets both on my API and Web. If I try them individually, both work fine. What I mean is: Broadcast::routes(['middleware' => 'web']); // this works for my Laravel website Broadcast::routes(['middleware' => 'auth:api']); // this works for my api However, if I want to use both at the same time like this: Broadcast::routes(['middleware' => ['auth:api', 'web']]); // doesn't work ... it crashes for both, which I suspect that it is

How to create a Pivot table in Laravel

核能气质少年 提交于 2019-12-07 17:04:12
问题 I have a sponsorship app I'm creating and trying to get a pivot table working between my users and kids, but when I have a user sponsor a kid, the pivot table kid_user is not populated with the kid_id or the user_id . Not sure what I'm missing. A Kid can have as many users (sponsors) as their slots allow them. Users can sponsor a kid, multiple kids or the same kid multiple times if needed. Here is my kid_user pivot table: public function up() { Schema::create('kid_user', function (Blueprint

laravel phpunit withexceptionhandling

廉价感情. 提交于 2019-12-07 15:50:04
问题 I'm in the process of writing a web app using Laravel 5.5 and Vue.js. PHPUnit version is 6.3.1. I'm testing for validation errors when a user registers using Form Requests. Route: // web.php Route::post('/register', 'Auth\RegisterController@store')->name('register.store'); This is my passing test: /** @test */ function validation_fails_if_username_is_missing() { $this->withExceptionHandling(); $this->json('POST', route('register.store'), [ 'email' => 'johndoe@example.com', 'password' =>

Remove index.php from URL of Laravel

天涯浪子 提交于 2019-12-07 13:15:28
I am using Laravel 5.5.12 in Linux Mint.I am using LAMP stack. I would like to remove index.php from URL. My mod_rewrite apache module enabled. My .htaccess file located in public folder and it contains following code. <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> Options +FollowSymLinks # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L

How can I configure an SCP/SFTP file storage?

大兔子大兔子 提交于 2019-12-07 07:25:42
问题 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. 回答1: 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

post request using axios on Laravel 5.5

拟墨画扇 提交于 2019-12-07 06:44:48
问题 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 回答1: This is happening because of the csrf-token. Just add meta tag with the csrf-token in the <head> and add

Create dynamic Laravel accessor

不打扰是莪最后的温柔 提交于 2019-12-07 05:46:50
问题 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

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

大城市里の小女人 提交于 2019-12-06 18:18:03
问题 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()); });

Laravel 5.5 Validate multiple file upload

谁都会走 提交于 2019-12-06 06:21:38
问题 How do I validate multiple file uploads using only one validation on laravel? $this->validate($request, [ 'project' => 'required|exists:project_details,id', 'location' => 'exists:project_details,location', 'plant_id' => 'exists:project_details,plant_id', 'capacity' => 'required|max:20', 'brief_description' => 'nullable|max:300', 'incident_details' => 'required|max:300', 'other_comments' => 'nullable|max:300', 'attachments.*' => 'required|file|mimes:xlsx,xls,csv,jpg,jpeg,png,bmp,doc,docx,pdf

how to change api_token column in token guard

て烟熏妆下的殇ゞ 提交于 2019-12-06 03:22:57
Laravel 5.5 I want to change direction of api token that used in TokenGaurd so, i created a custom guard named CafeTokenGaurd extends TokenGuard, i define __construct function into it like what i want, something like this: public function __construct(UserProvider $provider, Request $request) { parent::__construct($provider, $request); $this->inputKey = 'api_key'; // I want changing this part $this->storageKey = 'api_key'; } Now i want to define api_key from relation with users table like this: device_user table -> token i want to define specific tokens for each devices user have, and i want to