laravel-4

Laravel: Validation unique on update

≯℡__Kan透↙ 提交于 2019-12-17 23:44:08
问题 I know this question has been asked many times before but no one explains how to get the id when you're validating in the model. 'email' => 'unique:users,email_address,10' My validation rule is in the model so how do I pass the ID of the record to the validation rule. Here is my models/User protected $rules_update = [ 'email_address' => 'required|email|unique:users,email_address,'.$id, 'first_name' => "required", 'last_name' => "required", 'password' => "required|min:6|same:password_confirm",

Add sql table column before or after specific other column - by migrations in Laravel 4.1

ぐ巨炮叔叔 提交于 2019-12-17 23:15:18
问题 Table 'users': |id|name|address|post_code|deleted_at|created_at| and I want add column 'phone_nr' somewhere between 'id' and 'deleted_at' Is it possible by migrations in Laravel 4.1? 回答1: Yes. Create a new migration using php artisan migrate:make update_users_table . Then use the table command as follows (if you're using MySQL!): Schema::table('users', function($table) { $table->string('phone_nr')->after('id'); }); Once you've finished your migration, save it and run it using php artisan

Laravel 4: making a combination of values/columns unique

与世无争的帅哥 提交于 2019-12-17 23:06:35
问题 I'm importing a bunch of csv entries in my database with Laravel 4. I can't really point at one column that has to be unique, it's a combination of 5 columns that makes it unique. However: how does one define this in Laravel? Option 1: schema builder You can use the $table->unique('email') method, but that only seems to allow one column, not a combination of columns. Option 2: Validation Less preferable, but I could validate the model before inserting it. However, again, using 'unique:[table]

Laravel - last login date and time timestamp

强颜欢笑 提交于 2019-12-17 22:33:50
问题 I know there are fields automatically inserted (e.g. updated_at and created_at ) but I was wondering if there is like an Eloquent method timestamp() or the Laravel way to produce timestamps? For instance, I want to record a timestamp every time a user logs in to my system and store it into the database, so we can see each user's last login date and time details. 回答1: You may observe the auth.login event and update the user's last login time. See the first example in the documentation for

“laravel.log” could not be opened: failed to open stream [duplicate]

ε祈祈猫儿з 提交于 2019-12-17 22:26:35
问题 This question already has answers here : How to fix Error: laravel.log could not be opened? (20 answers) Closed 20 days ago . I have setup Laravel homestead on a local OSX machine, everything seemed to be going smoothly until I tried to open example.app:8000 and got this error: Error in exception handler: The stream or file "/home/vagrant/Code/example/app/storage/logs/laravel.log" could not be opened: failed to open stream: Protocol error in /home/vagrant/Code/example/bootstrap/compiled.php

Eloquent with nested whereHas

家住魔仙堡 提交于 2019-12-17 22:25:29
问题 Currently I have this whereHas in a collection of my model: $query = self::whereHas('club', function($q) use ($search) { $q->whereHas('owner', function($q) use ($search) { $q->where('name', 'LIKE', '%'. $search .'%'); }); }); I was under the impression the code above could be as such: $query = self::whereHas('club.owner', function($q) use ($search) { $q->where('name', 'LIKE', '%'. $search .'%'); }); I'm aware this is already a lot of power, but even then, if I have a nested relationship 5

Foreign keys in Laravel 4 migrations issue

走远了吗. 提交于 2019-12-17 22:11:04
问题 I've just created a new Laravel 4 project and am finding strange things happening with the foreign key aspect of the schema builder. If I use the ->foreign() method in any of my migrations I get thrown MySQL errors 150 and general error 1005. According to the documentation at laravel.com/docs the two scenario's at the bottom should work? Anyone know why they don't? The following does work: Schema::create('areas', function($table) { $table->engine ='InnoDB'; $table->increments('id'); $table-

Installing Laravel 4.1 in Windows 7 // Make .phar file globally available to windows command line

大城市里の小女人 提交于 2019-12-17 21:57:23
问题 i have some problems installing Laravel 4.1 in Windows 7 via the first method explained in the Laravel documentation ( http://laravel.com/docs/installation#install-laravel ). So I downloaded the laravel.phar file and put it in my path ( System32 ). Which would be the equivalent of /usr/bin in linux based systems? ( I also added .PHAR in the PATHEXT system variable ). When i ran the laravel command from the command line it didn't know how to open it, so i chose to open it with php.exe. Now,

Laravel 4.1 installation with composer in xampp

妖精的绣舞 提交于 2019-12-17 21:52:52
问题 I wanted to try out the Laravel 4.1 but unfortunately got stuck at the very beginning. When i try to install it using composer as mentioned in the Laravel 4.1 documentation , i get the following error while running "composer create-project laravel/laravel laravelProject --prefer-dist": [Composer\Downloader\TransportException] The "http://packagist.org/p/illuminate/filesystem$a5912ddb14272c0efa16e821a25bb68e39d3bac736aee7de62cb5641fd7133e3.json" file could not be downloaded: failed to open

How to load view from alternative directory in Laravel 4

Deadly 提交于 2019-12-17 21:47:36
问题 In my Laravel 4 application's root directory, I have a folder themes . Inside the themes folder, I have default and azure . How can I access view from this themes/default folder in a specific route. Route::get('{slug}', function($slug) { // make view from themes/default here }); My directory structure: -app --themes ---default ---azure I need to load views from localhost/laravel/app/themes/default folder. Please explain this. 回答1: This is entirely possible with Laravel 4. What you're after is