laravel-6

How to use One Laravel Controller with Multiple Guard instead of Duplicating the Controller

六月ゝ 毕业季﹏ 提交于 2021-02-11 15:42:16
问题 I have two Guards Admin User Also i have created controllers where user can manage his own data and admin can also manage user data. So i created two Controllers Controllers Admin EducatonBackgroundController User EducationBackgroundController In User/EducationBackgroundController i have this function which fetch education background of a current logged user and display on the user view public function index(Education $education) { try { $educations = $education->where('user_id',$this-

Laravel 6 Event Listener Mailable Queue unable to access

亡梦爱人 提交于 2021-02-11 12:09:46
问题 Environment: php: 7.4.2 laravel: 6.15.0 Scenario : Upon user registration, event(new NewUserHasRegisteredEvent($user)); is triggered. In my EventServiceProvider.php protected $listen = [ NewUserHasRegisteredEvent::class => [ \App\Listeners\WelcomeNewUserListener::class, ], ]; My NewUserHasRegisteredEvent.php <?php namespace App\Events; use App\User; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PresenceChannel; use

Return validation error message as JSON - Laravel 6

懵懂的女人 提交于 2021-02-10 16:51:14
问题 I want to return a failed validation attempt message in JSON. I used something like this before, which was working on Laravel 5, I believe... if ($validator->fails()) { return response()->json($validator->messages(), 200); } However, for our new project we are using Laravel 6 and the above just returns a blank page. In Laravel 6 the following returns the error message successfully, albeit not in JSON... if ($validator->fails()) { $msg = $validator->messages(); dd($msg); } There must be a

Missing required parameter for route although parameter is passed in view

筅森魡賤 提交于 2021-01-29 19:12:03
问题 I got error like this: Missing required parameters for [Route: resumenes.show] [URI: resumenes/{resumen}]. (View: .../resources/views/resumenes/index.blade.php) Controller public function index() { $resumenes = Resumene::orderBy('title','ASC')->paginate(); return view('resumenes.index', compact('resumenes') ); } public function show(Resumene $resumen) { return view('resumenes.show', [ 'resumen'=> $resumen ]); } Routes Route::get('/resumenes/{resumen}', 'ResumeneController@show')->name(

Why is my validation rule not working in my Laravel Controller?

白昼怎懂夜的黑 提交于 2021-01-29 15:10:41
问题 I am trying to write a test that checks that a date is formatted correctly. Looking at the docs it seems pretty straight-forward. Here is my test. I am submitting an invalid date format to my controller: MyTest.php /** @test */ public function a_date_must_be_formatted_correctly() { $foo = factory(Foo::class)->raw([ 'date' => date('d/m/Y'), ]); $response = $this->postJson('api/v1/foo', $foo) ->assertStatus(422) ->assertJsonValidationErrors('date'); } Here is my controller method: public

Getting 404 in laravel 6.x

我的梦境 提交于 2021-01-29 10:18:16
问题 I have created ApiController in App\Http\Controllers\Api\v1 Also created auth using laravel/ui Default created function for front end working perfectly. But issue is when try to call the ApiController My API Rout e file is as below Route::group(['prefix' => 'api/v1', 'namespace' => 'Api\v1'], function () { Route::post('register', 'ApiController@register'); }); And my API controller look like namespace App\Http\Controllers\Api\v1; use App\Http\Controllers\Controller; use Illuminate\Http

Laravel 6 pathinfo() expects parameter 1 to be string, object given

好久不见. 提交于 2021-01-29 08:44:33
问题 This is where i get the error: $data = Excel::import($path, function($reader) {})->get(); I changed the load() to import() . I want to run this code in Laravel 6, but version 3 of MaatWebsiteExcel does not support load() . I've been searching for solutions, yet i cant find any.... This is my controller: namespace App\Http\Controllers; use App\Contact; use App\CsvData; use App\Http\Requests\CsvImportRequest; use Illuminate\Http\Request; use Maatwebsite\Excel\Facades\Excel; use Session; use DB;

Resource response is not wrapped with “data” [duplicate]

瘦欲@ 提交于 2021-01-28 11:31:10
问题 This question already has an answer here : Laravel paginate resources won't add meta (1 answer) Closed 12 months ago . I am very curious, why my resource response is not wrapped in data : This is my resource: App\Http\Resources\CategoryResource Object ( [resource] => stdClass Object ( [id] => 12 [title] => Category [description] => <p>Test</p> [with] => Array ( ) [additional] => Array ( ) ) Once this resource is returned like this: $response = $this->client->getApiResponse('/api/category/'.

Laravel Schedule withoutOverlapping() is not working with runInBackground()

痞子三分冷 提交于 2021-01-28 05:13:06
问题 I'm trying to setup schedule for my commands in /app/Console/Kernel.php and found out that withoutOverlapping() doesnt work with runInBackground() This works without overlaps: $schedule ->command('test:update') ->withoutOverlapping(); This overlaps tasks: $schedule ->command('test:update') ->withoutOverlapping() ->runInBackground(); 回答1: In the first case, it was working without overlaps because command was running in the foreground and scheduler was busy processing this command thus didn't

Laravel error in creating a table with two timestamp columns

耗尽温柔 提交于 2021-01-28 04:40:23
问题 I created a table in Laravel 6.6 with the following definition. public function up() { Schema::create('quarters', function (Blueprint $table) { $table->integer('quarter_id')->unsigned(); $table->integer('year')->unsigned(); $table->integer('quarter_num')->unsigned(); $table->timestamp('valid_from'); $table->timestamp('valid_to'); // <------ error on this line $table->string('description')->nullable(); $table->timestamps(); $table->primary('quarter_id'); }); } When I run the migration command