laravel-5.5

How can I simulate logging out after using Passport::actingAs in a unit or integration test?

我是研究僧i 提交于 2019-12-02 03:22:45
问题 I have a test where I simulate logging in, then afterwards I want to test things as if I was not logged in. Like so. // log in as user with id 2 $id = 2; Passport::actingAs(User::findOrFail($id)); testSomeStuff() ... // now I want to test things as if I was not logged in Is there a way to do this in one test function? I'm using Laravel 5.6 and Passport 5. 回答1: Try this in your test $this->refreshApplication(); Had the same issue and this is the only thing that worked for me EDIT: It seems to

Laravel 5.6 - How to get auth()->user() or $response->user() in api controller?

北城以北 提交于 2019-12-01 21:30:20
问题 In api.php routes file below, there are public routes and private routes: Route::group(['namespace' => 'API'], function() { // Public routes (auth not required) Route::group([], function() { Route::get('/testauth1', 'TestController@testauth1'); // more public routes... }); // Private routes (auth required) Route::group(['middleware' => 'auth:api'], function() { Route::get('/testauth2', 'TestController@testauth2'); // more private routes... }); }); In the TestContoller these are the 2 methods

How to resolve the error: SQL authentication method unknown in Laravel-MySql

谁都会走 提交于 2019-12-01 20:37:03
问题 I using docker and I have a container of Laravel Framework 5.5.25 and other with mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL). in my configuration of docker compose I have this: version: "2" services: mysql: image: mysql ports: - "3307:3306" command: --sql_mode="" So, when Laravel try to connect to MySql I have this error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from 回答1: You have to use legacy style

How to resolve the error: SQL authentication method unknown in Laravel-MySql

ε祈祈猫儿з 提交于 2019-12-01 20:05:16
I using docker and I have a container of Laravel Framework 5.5.25 and other with mysql Ver 8.0.11 for Linux on x86_64 (MySQL Community Server - GPL). in my configuration of docker compose I have this: version: "2" services: mysql: image: mysql ports: - "3307:3306" command: --sql_mode="" So, when Laravel try to connect to MySql I have this error: SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from You have to use legacy style passwords for MySQL 8 and PHP7+: ALTER USER 'username'@'ip_address' IDENTIFIED WITH mysql_native_password BY

Class ' Form' not found in view-file.blade.php

≯℡__Kan透↙ 提交于 2019-12-01 18:42:06
I'm trying to render a text input field in my view file. I keep getting this error: "Class 'form' not found in view-file.blade.php" Template: @extends('layouts.app') @section('content') <h1>New</h1> {{ Form::open() }} {{ Form::text('my-name') }} {{ Form::close() }} @endsection Composer.json "require": { "php": ">=7.0.0", "fideloper/proxy": "~3.3", "laravel/framework": "5.5.*", "laravel/tinker": "~1.0", "laravelcollective/html": "^5.5.0" }, app.php (config) 'providers' => [ /* * Laravel Framework Service Providers... */ Illuminate\Auth\AuthServiceProvider::class, Illuminate\Broadcasting

Make custom query builder method (query scope) for all models in Laravel 5.5

喜你入骨 提交于 2019-12-01 09:31:37
I have multiple models, all with timestamps. I'm often using whereDate to get all rows from today and yesterday, like this: ModelName::whereDate('created_at', now()->today())->get(); ModelName::whereDate('created_at', now()->yesterday())->get(); I want to have it shorter, simplier, like: ModelName::today()->get(); ModelName::yesterday()->get(); I can not find any methods to do this, so I found in documentation that I can make own "scopes". The problem is, that I can make it for specified model, but I can not find a way to make it globally, for all models. Now I need to paste this scope methods

Make custom query builder method (query scope) for all models in Laravel 5.5

时光毁灭记忆、已成空白 提交于 2019-12-01 08:46:58
问题 I have multiple models, all with timestamps. I'm often using whereDate to get all rows from today and yesterday, like this: ModelName::whereDate('created_at', now()->today())->get(); ModelName::whereDate('created_at', now()->yesterday())->get(); I want to have it shorter, simplier, like: ModelName::today()->get(); ModelName::yesterday()->get(); I can not find any methods to do this, so I found in documentation that I can make own "scopes". The problem is, that I can make it for specified

Laravel 5.6 Passport driver not working in socket.io and gives unauthorized exception

会有一股神秘感。 提交于 2019-12-01 07:36:26
问题 Below code was working perfectly when the driver was api. Then I created a new project and changed the driver to passport. Now, I am always getting Error: Unauthorized. I can confirm that the request header has authorization token code in the browser. Please check the below image by clicking it and click on zoom to see the image with better quality. Am I missing anything in below code? Please let me know if you need more info. bootstrap.js import Echo from 'laravel-echo' window.Echo = new

Redirect automatically when user session expires in Laravel 5.5

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 01:49:11
I want to redirect automatically to my login page when a user session expires using Laravel functions. I do redirect when a user try to access to another page and the session expires. I have set a lifetime which helps to log out automatically because of user's inactivity, and what I want is to redirect instantly when that session timeout. I tried using JavaScript to timeout but this is not functional when the user is using more than one page at time. I also tried using AJAX, sending requests to check session status every minute, this works but when the project is in production there's many

Laravel 5.5 API resources for collections (standalone data)

邮差的信 提交于 2019-11-30 14:01:41
问题 I was wondering if it is possible to define different data for item resource and collection resource. For collection I only want to send ['id', 'title', 'slug'] but the item resource will contain extra details ['id', 'title', 'slug', 'user', etc.] I want to achieve something like: class PageResource extends Resource { /** * Transform the resource into an array. * * @param \Illuminate\Http\Request * @return array */ public function toArray($request) { return [ 'id' => $this->id, 'title' =>