laravel-5

how to sort a json object in laravel

て烟熏妆下的殇ゞ 提交于 2020-12-12 12:28:05
问题 i have the following response, how to sort it depending on the distnace { "Message": "Done.", "Status": true, "InnerData": [ { "id": 66, "name": "tito", "distance": 74, }, { "id": 67, "name": "liver pool", "distance": 83 }, { "id": 67, "name": "Text", "distance": 72 } ] } i tried the usort but i didn't make it. i also tried this answer here but it seems to be different than the one i need 回答1: In pure PHP 7 <?php $json = '{ "Message": "Done.", "Status": true, "InnerData": [ { "id": 66, "name"

Laravel Query Builder: select TIMESTAMP as Carbon object

前提是你 提交于 2020-12-12 01:58:08
问题 Is it possible to select a timestamp column as a Carbon date object using the query builder? DateCreated in the snippet below: $entities = DB::table('translation_review as tr') ... ->select('tr.AuthorID', 't.LanguageID', 't.DateCreated' /* <--- this one! */) ->get(); Update 1 : I have solved this manually by iterating over the result set and changing the DateChanged property manually, but I am not satisfied with this solution. It feels inelegant. foreach ($entities as $entity) $entity-

How to change default url from localhost:8000 to other Ip in laravel when we run “php artisan serve”

与世无争的帅哥 提交于 2020-12-08 07:23:29
问题 I am running php artisan serve command by default the result is : Laravel development server started: http://127.0.0.1:8000 I want to change pointing to other ip 回答1: # php artisan serve --help Usage: serve [options] Options: --host[=HOST] The host address to serve the application on. [default: "127.0.0.1"] --port[=PORT] The port to serve the application on. [default: 8000] -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application

Laravel Eloquent join vs with

爷,独闯天下 提交于 2020-12-05 06:18:51
问题 I see that join is (by default inner join) and its returning all columns but it takes almost the same time as with keyword for just 1000 data. $user->join(‘profiles’, ‘users.id’, ‘=’, ‘profiles.user_id’) - generates the below query. select * from `users` inner join `profiles` on `users`.`id` = `profiles`.`user_id` where `first_name` LIKE '%a%'` User::with(‘profile’) - this eager loading outputs the below query select * from `users` where exists (select * from `profiles` where `users`.`id` =

convert null values into empty string in laravel 5.4

折月煮酒 提交于 2020-12-04 03:15:34
问题 I want to convert all null with empty string I have used array_walk_recursive but I haven't got what I want please help me to figure it out what I have done wrong here. protected function setData($key, $value) { $this->data[$key] = $value; array_walk_recursive($this->data, function (&$item, $key) { $item = null === $item ? '' : $item; }); return $this->data; } 回答1: well, that's just a lamp mistake in eloquent we always get result in eloquent object and here I'm passing eloquent object inside

convert null values into empty string in laravel 5.4

倖福魔咒の 提交于 2020-12-04 03:15:31
问题 I want to convert all null with empty string I have used array_walk_recursive but I haven't got what I want please help me to figure it out what I have done wrong here. protected function setData($key, $value) { $this->data[$key] = $value; array_walk_recursive($this->data, function (&$item, $key) { $item = null === $item ? '' : $item; }); return $this->data; } 回答1: well, that's just a lamp mistake in eloquent we always get result in eloquent object and here I'm passing eloquent object inside

How to fake image upload for testing with Intervention image package using Laravel

流过昼夜 提交于 2020-12-03 21:44:12
问题 I have a test asserting that images can be uploaded. Here is the code... // Test $file = UploadedFile::fake()->image('image_one.jpg'); Storage::fake('public'); $response = $this->post('/api/images', [ 'images' => $file ]); Then in controller i am doing something simpler.. $file->store('images', 'public'); And asserting couple of things. and it works like charm. But now i need to resize the image using Intervention image package. for that i have a following code: Image::make($file) ->resize

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

How to add custom config file to app/config in Laravel 5?

为君一笑 提交于 2020-11-30 04:39:03
问题 I want to add custom_config.php to app/config directory of my Laravel 5 project, but can't find any article explaining this process. How is this done? 回答1: You can easily add a new file to the config folder. This file should return configuration values. Check other config files for reference. Say constants.php is like so <?php return array( 'pagination' => array( 'items_per_page' => 10 ), ); You can now access this config file from anywhere by either using the Config Facade or the config()