eloquent

Can I use camelCase with Laravel 4 eloquent?

假装没事ソ 提交于 2020-02-03 05:18:06
问题 I have existing data in a mysql db whose columns are camelCased. I can't change them to snake case. For instance: when I try to use "jobRole", I get "job_role". I want it to be "jobRole". Is there a setting in laravel to support this? I've read about mutators but don't understand them. Is that the solution? If so, how do I do this? 回答1: Discovered you can do this. In the model, redefine "snakeAttributes" to "false" like this: class YourModel extends Eloquent{ public static $snakeAttributes =

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 Eloquent where field is X or null

限于喜欢 提交于 2020-01-30 19:31:11
问题 I have a table like this: table - field1: tinyint - field2: varchar (nullable) - datefield: timestamp (nullable) Now I want to get all entries where field1 is 1, field2 is null and where datefield is smaller than X or null. I already tried something like this: $query = Model::where('field1', 1) ->whereNull('field2') ->where('datefield', '<', $date) ->orWhereNull('datefield'); but thats not working. I always get every entry where datefield is null. It doesn't matter what the other fields are.

How to check that inputted data is in foreach or not?

心已入冬 提交于 2020-01-30 11:54:46
问题 I have two rounds "first and knock-out". Only 4 teams can go to knock-out round, those who got the highest point on the first round. Now firstly, I want to select that 4 teams from first round and then check whether the inputted team is on the selected 4 teams or not. Take a look to my code(So far I tried). My problem is, if I input two team names from below dd($kos) it will save the $matches->round="first"Here I attach a dd($kos),if my inputted data is in the dd($kos) only then the $matches

How to check that inputted data is in foreach or not?

我的未来我决定 提交于 2020-01-30 11:54:06
问题 I have two rounds "first and knock-out". Only 4 teams can go to knock-out round, those who got the highest point on the first round. Now firstly, I want to select that 4 teams from first round and then check whether the inputted team is on the selected 4 teams or not. Take a look to my code(So far I tried). My problem is, if I input two team names from below dd($kos) it will save the $matches->round="first"Here I attach a dd($kos),if my inputted data is in the dd($kos) only then the $matches

how to retrieve different names from same table with different ids on join laravel

谁都会走 提交于 2020-01-30 09:29:05
问题 I need to get names from destinations table for each from_destination_id and to_destination_id as fromDestinationName and toDestinationName $bookingTransfersData = DB::table('transfers as t') ->select('t.periodStart as periodStart', 't.periodEnd as periodEnd','t.days','t.transfer_id','t.cost_round_trip', 't.cost_one_way','t.status','d.destination_id as destinationId','d.name as destinationName', 't.type', 'tf.name as officeName', 'ag.name as agencyName', 'u.name as userName', 'v.name as

Eloquent - Eager Loading Relationship

眉间皱痕 提交于 2020-01-30 05:29:04
问题 I'm trying to figure out how to eager load data from a related table. I have 2 models Group and GroupTextPost . Group.php <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Group extends Model { protected $table = 'group'; public function type() { return $this->hasOne('\App\Models\GroupType'); } public function user() { return $this->belongsTo('\App\Models\User'); } public function messages() { return $this->hasMany('\App\Models\GroupTextPost'); } } GroupTextPost.php <

How to remove index number from laravel eloquent unique

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-30 03:18:16
问题 I am using a query that returns value perfectly but it adds key number to the collection. How can I remove the index number? Here is the retrieved data { "data": { "0": { "id": 135, "conversation_id": 11, "last_sender": null, "last_reciever": { "id": 54, "userName": "Sadek", "profilePic": "Nir7zgorNT2dmwcXJdhNK3ZmPAltmkEnj0SXDCDC.png", "firstName": "Sadek", "lastName": "Hossain" }, "msg": "hello guys how are you", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 16:56:41

How to remove index number from laravel eloquent unique

泪湿孤枕 提交于 2020-01-30 03:17:46
问题 I am using a query that returns value perfectly but it adds key number to the collection. How can I remove the index number? Here is the retrieved data { "data": { "0": { "id": 135, "conversation_id": 11, "last_sender": null, "last_reciever": { "id": 54, "userName": "Sadek", "profilePic": "Nir7zgorNT2dmwcXJdhNK3ZmPAltmkEnj0SXDCDC.png", "firstName": "Sadek", "lastName": "Hossain" }, "msg": "hello guys how are you", "attachment": null, "deleted": 0, "seen": 0, "created_at": "2017-10-17 16:56:41