laravel

Modify the wrapping of the outer-most resource in Laravel

亡梦爱人 提交于 2021-01-29 13:02:22
问题 I want to modify the wrapping of the outer-most resource. In documentation there is a solution on how to remove the default "data" wrap but I can't find how to change it to another key. 回答1: Remove the default via Resource::withoutWrapping() , and then manually wrap the data in the Resource class: public function toArray() { return [ "my-custom-key" => $this->resource->toArray() ]; } 来源: https://stackoverflow.com/questions/57869078/modify-the-wrapping-of-the-outer-most-resource-in-laravel

How can I create dynamic public properties and data via a parent component to a child component in livewire / laravel?

孤街浪徒 提交于 2021-01-29 12:48:05
问题 In a Laravel 8 application I have two components. Input.php and Form.php Input.php <?php namespace App\Http\Livewire\General; use Livewire\Component; class Input extends Component { public $name; public $model; public $label; public function render() { return view('livewire.general.input'); } } input.blade.php <div class="mt-3"> <label for="{{ $name }}" class="sr-only" > $label </label> <input wire:model="{{ $model }}" id="{{ $name }}" placeholder="{{ $label }}" autocomplete="off" class="w

laravel vue getting info by hidden field

China☆狼群 提交于 2021-01-29 12:47:58
问题 I need to pass logged user id to back-end and I have vuex store so I can get my user info like {{currentUser.id}} the problem is i cannot pass it to back-end it gives me validation error that user_id is required while i have this hidden input in my form <input type="hidden" name="user_id" :value="currentUser.id"> for normal inputs i have v-model like v-model="project.title" which is not possible to use on hidden fields. The question here is how can I pass my user_id to back-end? Code <script>

Laravel Schedule Task Output

只愿长相守 提交于 2021-01-29 12:39:29
问题 As per documentation https://laravel.com/docs/5.5/scheduling#task-output $schedule->command('emails:send')->daily()->sendOutputTo($filePath); I set the file path $schedule->command('word:day')->hourly()->appendOutputTo(storage_path('logs/test_logos.log')); But log file is empty? Cant see task output Command Code public function handle() { $this->info('Word of the Day sent to All Users'); } 来源: https://stackoverflow.com/questions/52253846/laravel-schedule-task-output

Illuminate query builder, how to convert dates to Carbon object

喜你入骨 提交于 2021-01-29 11:53:37
问题 Is there any chance to use Illuminate Query builder to get dates as Carbon objects instead of strings? For example: $user=DB::table('users')->select(["id","lastLogin"])->where("id",1)->first(); $user->lastLogin; // <--- Carbon instead of string! 回答1: You can use Carbon::parse($user->lastLogin) , but I think there is no native way to get dates as carbon objects without using eloquent. An example is this answer on stackoverflow. I think working with eloquent models will make the work much

SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time,

陌路散爱 提交于 2021-01-29 11:34:39
问题 I try to connect 2 database in my Laravel 5.6 project, but i got error like this SQLSTATE[HY000] [2002] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (SQL: select * from mt_merchant ) I tried following code: .env 1st db connection (this is in my local server) DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=thedaldb DB_USERNAME=root DB

The GET method is not supported for this route. Supported methods: POST / PATCH / DELETE

亡梦爱人 提交于 2021-01-29 11:29:56
问题 I have created manually some routes for customizing purposes. Here is my code: Route::post('/dashboard/show-all-notifications', [App\Http\Controllers\DashboardController::class, 'showAllNotifications']); Form {!! Form::open(['method'=>'POST','action'=>['App\Http\Controllers\DashboardController@showAllNotifications']]) !!} {!! Form::submit('Show all notifications', ['class'=>'btn btn-sm btn-primary btn-block']) !!} {!! Form::close() !!} DashboardController public function showAllNotifications

laravel reset password not resetting the password

你说的曾经没有我的故事 提交于 2021-01-29 11:26:00
问题 I am using laravel 6. I am trying to implement forgot password for my laravel project for the first time. I have customize the default design for login, forgot password, reset password pages. I have integrated mailtrap for sending email. I have successfully implemented flow like - click forgot password link get page on which user enters email and click to send reset link gets the email of resetting link and data like email, token , created_at stores in password_reset table on click of reset

Can I customize rate limiting in Laravel?

99封情书 提交于 2021-01-29 11:17:11
问题 Is there any way through which the rate limit duration can be customized? For instance, I am using the default Laravel rate limiter. I would want to have something like - allow 10 requests per hour . 回答1: Laravel throttle is a rate limiter for the Laravel application. You can make your request safe implementing laravel throttle by route group like : Route::group(['middleware' => 'throttle:10,60'], function () { Route::get('your_route', 'YourController@your_method'); Route::post('your_route2',

Eloquent: use a modificator in WhereIn

五迷三道 提交于 2021-01-29 11:10:48
问题 in my code i've create a modificator and generate the column chiave_composita. If i run this code i've obtain the data TransazioniOrigine::all()->pluck('chiave_composita')->toArray() but if i use this code $origine = TransazioniOrigine::all()->pluck('chiave_composita')->toArray(); $destinazione = Transazioni::all()->pluck('transazioneKey')->toArray(); $diff = array_diff($origine, $destinazione); dd(TransazioniOrigine::whereIn('chiave_composita', $diff)->get()); i have this errror: Il nome di