laravel-5.1

Laravel 5.1 Eager Loading - belongsToMany with parameter

只谈情不闲聊 提交于 2021-02-07 10:58:23
问题 I have this relationship in my Model: public function modulesData($module) { return $this->belongsToMany($module) ->withTimestamps(); } What I want is to eagerload a dynamic relation of my model. But how can I do this? I use this code to eagerload my relation, but how can I add the parameter $module ? $model->with(['modulesData'])->get(); Thanks for reply. 回答1: Consider the following: Define the fallback function to your Model: public function __call($name, $arguments) { if (strpos($name,

POST request to Clevertap using GuzzleHttp

回眸只為那壹抹淺笑 提交于 2021-01-28 11:26:57
问题 I am using Laravel 5.1 and Guzzlehttp 6.1 to make post request to clevertap. $client = new \GuzzleHttp\Client(['headers' => ['X-CleverTap-Account-Id' => '**********','X-CleverTap-Passcode'=>'*************8']]); $result = $client->request('POST','https://api.clevertap.com/1/upload',["d"=>[ "identity"=>"1189549", "ts"=>1419421212, "type"=>"profile", "profileData"=>[ "Name"=>"Jack Montana", "Email"=>"jack@gmail.com", "Phone"=>"+14155551234", "Gender"=>"M", "Employed"=>"Y", "Education"=>"Graduate

Set httpOnly flag for CSRF token in Laravel

孤街浪徒 提交于 2020-12-29 09:57:33
问题 I'm building an application in Laravel 5.1 for a client. After I finished the application I got back an pentest report which tells me to add a HttpOnly flag. I added 'secure' => true and 'http_only' => true to app/config/session.php. The httpOnly flag is set for all sessions, except the XSRF-TOKEN session. How am I able to set this flag as well? 回答1: You are able to overwrite the method addCookieToResponse($request, $response) in App\Http\Middleware\VerifyCsrfToken /** * Add the CSRF token to

Set httpOnly flag for CSRF token in Laravel

China☆狼群 提交于 2020-12-29 09:57:19
问题 I'm building an application in Laravel 5.1 for a client. After I finished the application I got back an pentest report which tells me to add a HttpOnly flag. I added 'secure' => true and 'http_only' => true to app/config/session.php. The httpOnly flag is set for all sessions, except the XSRF-TOKEN session. How am I able to set this flag as well? 回答1: You are able to overwrite the method addCookieToResponse($request, $response) in App\Http\Middleware\VerifyCsrfToken /** * Add the CSRF token to

How to Display Validation Errors Next to Each Related Input Field in Laravel 5?

坚强是说给别人听的谎言 提交于 2020-12-27 17:01:16
问题 Default solution is trivial: @if (count($errors) > 0) <ul id="login-validation-errors" class="validation-errors"> @foreach ($errors->all() as $error) <li class="validation-error-item">{{ $error }}</li> @endforeach </ul> @endif and I can include errors.blade.php anywhere. Is there any way to extract each element and display it next to input field that holds the value that failed? I assume that would require me to define a lot of conditional if statements next to each input, right? How to sort

Laravel 5.1 Php artisan commands not working after composer update

跟風遠走 提交于 2020-12-13 18:46:47
问题 here is my composer.json require snippet. "require": { "php": ">=5.5.9", "laravel/framework": "5.1.35", "aws/aws-sdk-php-laravel": "~3.0", "lucadegasperi/oauth2-server-laravel": "5.1.*", "bosnadev/repositories": " 0.*", "laravelcollective/html": "5.1.*", "cartalyst/stripe-laravel": "3.0.*" }, I ran composer update in order to add new AWS services. but then I noted that all the vendor files are updated because of composer update command. now I'm getting error when I ran php artisan commands.

Laravel 5.1 Php artisan commands not working after composer update

白昼怎懂夜的黑 提交于 2020-12-13 18:44:11
问题 here is my composer.json require snippet. "require": { "php": ">=5.5.9", "laravel/framework": "5.1.35", "aws/aws-sdk-php-laravel": "~3.0", "lucadegasperi/oauth2-server-laravel": "5.1.*", "bosnadev/repositories": " 0.*", "laravelcollective/html": "5.1.*", "cartalyst/stripe-laravel": "3.0.*" }, I ran composer update in order to add new AWS services. but then I noted that all the vendor files are updated because of composer update command. now I'm getting error when I ran php artisan commands.

Laravel 5 - Task schedule withoutOverlapping not working

蹲街弑〆低调 提交于 2020-12-02 06:55:19
问题 I try to run schedule on Laravel 5. Its work fine when I run this: $schedule->call(function() { // do something here.. })->everyMinute(); But when I add withoutOverlapping() , the scheduler never run the task: $schedule->call(function () { // do something here.. })->everyMinute()->name('job_name')->withoutOverlapping(); *these schedule code is written at /app/Console/Kernel.php 回答1: Delete ->everyMinute() when using ->withoutOverlapping() it will still run every minute but without overlapping

Laravel 5 - Task schedule withoutOverlapping not working

て烟熏妆下的殇ゞ 提交于 2020-12-02 06:53:21
问题 I try to run schedule on Laravel 5. Its work fine when I run this: $schedule->call(function() { // do something here.. })->everyMinute(); But when I add withoutOverlapping() , the scheduler never run the task: $schedule->call(function () { // do something here.. })->everyMinute()->name('job_name')->withoutOverlapping(); *these schedule code is written at /app/Console/Kernel.php 回答1: Delete ->everyMinute() when using ->withoutOverlapping() it will still run every minute but without overlapping

Laravel Collection get unique values from nested datastructure

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-01 12:11:16
问题 I want to use Laravel 5.1 Collection's Unique method to filter unique IDs from nested objects. Given the data structure { "key1": [ {"id": 1}, {"id": 1} ], "key2": [ {"id": 1}, {"id": 2} ] } I want to return the same datastructure with duplicate id 1 removed from "key 1". I wanted to use $unique = $collection->unique('id'); , but this doesn't seem to apply to a nested datastructure as I have. So I thought to use $collection $input = $request->all(); $collection = collect($input); $collection-