laravel-5.1

Create a Laravel Request object on the fly

自作多情 提交于 2020-07-04 06:08:18
问题 I'm handling data in one controller and want to pass it further into another controller to avoid duplicate code. Is there a way to set up a Request object that is needed in the other controller's store -method? I've traced down the Request inheritance and came to Symfony's Request object which has a request property that is in fact a ParameterBag that holds a method add to add parameters with values to it. I've tried the following but I'm getting null as result: $myRequest = new Request();

Laravel commands and jobs

天涯浪子 提交于 2020-07-04 05:49:56
问题 I was wondering what the difference is between the different command-like classes in Laravel 5.1. As far as I can tell Laravel 5.1 has the following available: Console commands ( artisan make:console ) Commands ( artisan make:command ) Handlers ( artisan make::command --handler ) Jobs ( artisan make:job ) I have come straight from 4.2 to 5.1 so I don't know what happened in between 4.2 and 5.1, but I have been told that the middle one ( just commands) are basically not really supposed to be

Laravel commands and jobs

a 夏天 提交于 2020-07-04 05:49:25
问题 I was wondering what the difference is between the different command-like classes in Laravel 5.1. As far as I can tell Laravel 5.1 has the following available: Console commands ( artisan make:console ) Commands ( artisan make:command ) Handlers ( artisan make::command --handler ) Jobs ( artisan make:job ) I have come straight from 4.2 to 5.1 so I don't know what happened in between 4.2 and 5.1, but I have been told that the middle one ( just commands) are basically not really supposed to be

Laravel 5.1 redirect within a transaction block

北战南征 提交于 2020-06-22 12:45:33
问题 I have a set of delete statements in my Laravel 5.1 application that I have put inside a transaction. I had my code like the following and was trying to return to the same page. But I was getting a blank page . My routes.php is fine. DB::transaction(function () use ($foo, $bar, $request) { // Delete from table abc $deletedFoo = DB::delete('delete from abc where id = ' . $foo); // Delete from table xyz $deletedBar = DB::delete('delete from xyz where id = ' . $bar); // Shows blank page $request

Laravel 5.1 redirect within a transaction block

你。 提交于 2020-06-22 12:45:07
问题 I have a set of delete statements in my Laravel 5.1 application that I have put inside a transaction. I had my code like the following and was trying to return to the same page. But I was getting a blank page . My routes.php is fine. DB::transaction(function () use ($foo, $bar, $request) { // Delete from table abc $deletedFoo = DB::delete('delete from abc where id = ' . $foo); // Delete from table xyz $deletedBar = DB::delete('delete from xyz where id = ' . $bar); // Shows blank page $request

Laravel : Handle findOrFail( ) on Fail

纵然是瞬间 提交于 2020-05-25 06:49:50
问题 I am looking for something which can be like findOrDo(). Like do this when data not found. Something could be like Model::findOrDo($id,function(){ return "Data not found"; }); Is there any similar thing in laravel that I can do this elegantly and beautifully ? *I tried googling but could not find one 回答1: use Illuminate\Database\Eloquent\ModelNotFoundException; // Will return a ModelNotFoundException if no user with that id try { $user = User::findOrFail($id); } // catch(Exception $e) catch

Laravel - calculate total size of directory?

假如想象 提交于 2020-04-16 02:18:31
问题 I'm trying to get the total size of $directory in Laravel, so far I've only been able to get the size of a single file using the size function. There doesn't seem to be any examples or documentation of this? Any input on this would be appreciated, thanks. 回答1: I don't think you can. Laravel 5 uses Flysystem Library, which has a sole method for retrieving file size. So using Laravel's File Facade (or Flysystem), you're only left with: $file_size = 0; foreach( File::allFiles('FULL_PATH_TO_DIR')

Get Laravel Models with All Attributes

你。 提交于 2020-03-17 10:08:34
问题 Is there a way to retrieve a model in Laravel with all the attributes, even if they're null? It seems to only return a model with the attributes that aren't null. The reason for this is that I have a function that will update the model attributes from an array, if the attributes exists in the model. I use the property_exists() function to check the model if it has a particular attribute before setting it. The array key and model attribute are expected to match, so that's how it works. It

Get Laravel Models with All Attributes

落爺英雄遲暮 提交于 2020-03-17 10:07:53
问题 Is there a way to retrieve a model in Laravel with all the attributes, even if they're null? It seems to only return a model with the attributes that aren't null. The reason for this is that I have a function that will update the model attributes from an array, if the attributes exists in the model. I use the property_exists() function to check the model if it has a particular attribute before setting it. The array key and model attribute are expected to match, so that's how it works. It

Laravel 5 - session put not working

旧时模样 提交于 2020-02-25 04:53:47
问题 Any ideas why the session variable is not set with this code ? public function commitTransaction($cluster,$transId) { try { $response = $this->client->request('PUT', 'https://' . $cluster . '/' . $transId, [ 'auth' => ['id', 'pass'], 'proxy' => '', 'verify' => false, 'json' => [ 'state' => 'VALIDATING' ] ]); $res = $response->getBody()->getContents(); session()->put('commit',$res); //dd($res); return $res; } catch (RequestException $e){ var_dump($e->getResponse()->getBody()->getContents()); }