laravel-5.1

Laravel cast route parameter to Integer

若如初见. 提交于 2020-02-04 01:49:14
问题 I really like the idea of Route Model Binding . Is there a similar way to cast parameters (which are Strings) to Intergers? The reason is that I often have the parameters year and month , but I would like to have it as an Integer, because the database seems to handle String and Integers in different ways. 回答1: Yes there is. You can use Route Binding similar to what I answered here. It's unfortunate that it exists but is not documented in the Laravel docs. 回答2: Update using PHP7, if anyone

Laravel 5 How to add multiple foreign key constraints to a User on creation?

时间秒杀一切 提交于 2020-02-02 12:13:13
问题 I now know that I can create a User using the haveMany relationship between a Region and User by doing this: $region = Region::find($data['region_id']); $region->users()->create([ 'username' => $data['username'], 'email' => $data['email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'password' => bcrypt($data['password']), ]); But what if there are multiple foreign keys, how do you create a user without making them fillable for more than 1 foreign key constraint?

Laravel 5 How to add multiple foreign key constraints to a User on creation?

▼魔方 西西 提交于 2020-02-02 12:10:06
问题 I now know that I can create a User using the haveMany relationship between a Region and User by doing this: $region = Region::find($data['region_id']); $region->users()->create([ 'username' => $data['username'], 'email' => $data['email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'password' => bcrypt($data['password']), ]); But what if there are multiple foreign keys, how do you create a user without making them fillable for more than 1 foreign key constraint?

Laravel 5.1.4 validation fail not populating old data when using RESTful routes

你说的曾经没有我的故事 提交于 2020-01-25 11:43:06
问题 I'm trying to build a back end admin area to add users to my application (I don't want users to register I want them to be set up by an admin). I've created the necessary controller and request. If the data is acceptable it submits via a POST request to domain.tld/admin/users and is stored via UserController@store . When the validation criteria isn't met, the user is sent back to the form (domain.tld/admin/users/create) and error messages are shown, but the fields aren't populated with the

Laravel 5.1 commands and jobs

旧街凉风 提交于 2020-01-25 11:01:07
问题 So, as far as I understand, commands are now jobs in Laravel 5.1. If I'd like to schedule a job, should I call a job from a command then (since the scheduler can only call commands and not jobs)? In the dummy setup of Laravel 5.1 there still is a app/Console/Commands folder with Inspire.php in it. The inspire command is called from the scheduler. So if I'd like to schedule a job, should I call a command and then call the job inside this command? 回答1: Commands are not jobs. Commands are

Laravel 5.1 commands and jobs

北慕城南 提交于 2020-01-25 11:01:05
问题 So, as far as I understand, commands are now jobs in Laravel 5.1. If I'd like to schedule a job, should I call a job from a command then (since the scheduler can only call commands and not jobs)? In the dummy setup of Laravel 5.1 there still is a app/Console/Commands folder with Inspire.php in it. The inspire command is called from the scheduler. So if I'd like to schedule a job, should I call a command and then call the job inside this command? 回答1: Commands are not jobs. Commands are

How to get the max ID in a Join Query in Laravel 5 (Integrity constraint violation:)

微笑、不失礼 提交于 2020-01-24 15:25:31
问题 My query is like this: $deals=DB::table('leadsheet') ->join('Deal', 'leadsheet.leadcode', '=', 'Deal.leadcode') ->join('benefits', 'leadsheet.leadcode', '=', 'benefits.leadcode') ->join('delegatedealinfo', 'leadsheet.leadcode', '=', 'delegatedealinfo.leadcode') ->join('vipbooking', 'leadsheet.leadcode', '=', 'vipbooking.leadcode') ->where('id', DB::raw("(select max(`id`) from vipbooking)")) ->where('leadsheet.leadcat', '=','Delegates') ->get(); So I have following tables: 1.leadsheet --

Laravel Deployment on Shared Hosting - 404 Error

喜夏-厌秋 提交于 2020-01-23 17:29:45
问题 I am trying to deploy my laravel 5.1 application on shared hosting cpanel. But I am getting 404 error. 404 Not Found The resource requested could not be found on this server! To upload the project, I make a clone of project directory and uploaded it on cpanel via their FileManger. Then move the Public folder items into Public_Html. My .htaccess file content is shown below: <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase / #

Laravel custom helper - undefined index SERVER_NAME

痞子三分冷 提交于 2020-01-23 11:06:07
问题 In Laravel 5.1, I created a custom helper file: custom.php which I load in composer.json : "autoload": { "files": [ "app/Helpers/custom.php" ] }, and it contains this method: function website() { return str_replace('dashboard.', '', $_SERVER['SERVER_NAME']); } It works as expected, but every time I do php artisan commands, I get a call stack and this message: Notice: Undefined index: SERVER_NAME in /path/to/custom.php on line 4 Why is this so? The method returns the correct value when run

Laravel custom validation message parameter

浪子不回头ぞ 提交于 2020-01-22 14:42:38
问题 I'm using laravel 5.1. I have a summernotejs form element. I've created a custom validation rule successfully, which takes the HTML provided from the form input, strips the tags, and does a strlen() call on the text content. Therefore I can see the length of a message without any tags in it. This is my validation rule: Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) { return strlen(strip_tags($value)) >= $parameters[0]; }); I call the validation rule by