eloquent

Laravel Eloquent. I try to intersect two intermediate table. Is there any query more efficient than this?

谁都会走 提交于 2021-01-28 19:35:48
问题 Laravel Eloquent. I try to intersect two intermediate table. Is there any query more efficient than this ? Unit Model : public function products() { return $this->belongsToMany('App\Product'); } public function users() { return $this->belongsToMany('App\User'); } Product Model : public function units() { return $this->belongsToMany('App\Unit'); } public function users() { return $this->belongsToMany('App\User'); } User Model : public function units() { return $this->belongsToMany('App\Unit');

Eloquent - join table on itself

喜夏-厌秋 提交于 2021-01-28 18:29:43
问题 I'm trying to join a table on itself but keep getting errors. Here is my current code. I've also tried Raw statement. Not sure which direction to go in at the moment. My code: $Calle = db('VoipBill') ->table('billing') ->join('billing', 'billing.srcnum', '=', 'billing.dstnum') ->where('acct_name', '100080_company') ->where('srcnum', $call->srcnum) ->whereBetween('calldate', [$set_time_lower, $set_time_upper]) ->get(); This is the error: SQLSTATE[42000]: Syntax error or access violation: 1066

Laravel 7: MariaDB in combination with Redis but Redis behaves slower with large objects

六月ゝ 毕业季﹏ 提交于 2021-01-28 11:54:47
问题 I have successfully implemented a combination of redis and mysql. At one section of my application I thought I would reduce load on mysql server and use redis until the data gets changed, however I observe that it's still faster when the same data is fetched from Mysql than redis. Here is scenario. User1: 10,000 records with seldom one off change in a day or so. What I do is whole object that fetches these 10K records, (serialized object of about 20mb in size) is saved to redis. The idea is

Laravel sort conversations by last message

跟風遠走 提交于 2021-01-28 09:29:50
问题 I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the query? As a sidenote to my code: Conversation contains a user ( user_id ) and a company associated ( company_id ). Company has a belongsToMany relation to user. Conversation::whereHas('company', function ($q) use ($userId) { $q->whereHas('users', function ($q1) use ($userId) { $q1->where('users.id'

Laravel sort conversations by last message

不打扰是莪最后的温柔 提交于 2021-01-28 09:23:41
问题 I have a Conversation model that has many ConversationMessage models. Now I want to sort the conversations based on the last message of the conversation. Basically like WhatsApp. How do I build the query? As a sidenote to my code: Conversation contains a user ( user_id ) and a company associated ( company_id ). Company has a belongsToMany relation to user. Conversation::whereHas('company', function ($q) use ($userId) { $q->whereHas('users', function ($q1) use ($userId) { $q1->where('users.id'

Laravel 3 way intermediate pivot table

人盡茶涼 提交于 2021-01-28 09:16:49
问题 I am having trouble defining the relationships in my Eloquent Models when using a 3 way intermediate pivot table. Here are the 4 tables in my database: users - id - name instruments - id - key instruments_users - id - user_id - instrument_id - level_id levels - id - key Instruments keys can be: guitare , piano , trumpet , etc. Levels keys can be: beginner , intermediate , expert , etc. Each user can play of 1 or more instrument. For each played instrument (relationship), we attribute a level

Laravel 3 way intermediate pivot table

此生再无相见时 提交于 2021-01-28 09:10:18
问题 I am having trouble defining the relationships in my Eloquent Models when using a 3 way intermediate pivot table. Here are the 4 tables in my database: users - id - name instruments - id - key instruments_users - id - user_id - instrument_id - level_id levels - id - key Instruments keys can be: guitare , piano , trumpet , etc. Levels keys can be: beginner , intermediate , expert , etc. Each user can play of 1 or more instrument. For each played instrument (relationship), we attribute a level

Laravel get last row value form many table in one to Many relationship

£可爱£侵袭症+ 提交于 2021-01-28 08:56:27
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-

Laravel get last row value form many table in one to Many relationship

自闭症网瘾萝莉.ら 提交于 2021-01-28 08:43:43
问题 I am building an application which has a model with one to many relationship. In the model, the student table has one to many relationship with student address details. I want to retrieve the last row from address details table. I am stuck on how to retrieve that data. I could not work out from similar answer on this website. My current solution is this $students = Student::with('visaDetails', 'addresses', 'instituteDetails', 'subAgents', 'staffDetails', 'commissionDetails', 'comments')-

How to login with Crypt encryption in login controller

百般思念 提交于 2021-01-28 08:03:39
问题 I am using Crypt:: for registration and login. My registration is successful but login is not successful. Please check the code and help me. public function Login(Request $request) { $this->validate($request, [ 'email' => 'required', 'password' => 'required', ]); $userdata = array( 'email' => $request->email, 'password' => \Crypt::encrypt($request->password) ); if (Auth::attempt($userdata) { echo "success";die(); } return "Ops! snap! seems like you provide an invalid login credentials"; } 回答1