eloquent

Where clause inside whereHas being ignored in Eloquent

给你一囗甜甜゛ 提交于 2019-12-24 06:34:48
问题 Im trying to make a query using whereHas with eloquent. The query is like this: $projects = Project::whereHas('investments', function($q) { $q->where('status','=','paid'); }) ->with('investments') ->get(); Im using Laravel 5.2 using a Postgres driver. The Project model is: public function investments() { return $this->hasMany('App\Investment'); } The investments model has: public function project() { return $this->belongsTo('App\Project'); } The projects table has fields id,fields... The

Laravel - Table not showing data

情到浓时终转凉″ 提交于 2019-12-24 06:28:42
问题 I'm building a time tracker and i'm trying to fill up a table with the total time logged for each category type for each month of the year. I'm not sure what i'm doing wrong but my table isn't showing any data. I believe it has to do with the way i'm calling my rows, each number represents the category_id, ex: <td>{{ $row[1] ?? '-' }}</td> This is supposed to be using the total time from category_id 1 which is Overtime Hours. Here's more info to make things more clear. Controller: public

Where query after whereHas not work as it should in Laravel 5.4

被刻印的时光 ゝ 提交于 2019-12-24 06:02:06
问题 In my case I have channels table that is in many to many relation with categories table. I want to fetch the channels that their categories contain a dynamic value like doing LIKE query on title of each category. but I need to check another columns of a channel by where clause. This is a channel structure: [ { "id": 87, "username": "ch1", "title": "ch title", "type": "channel", "members": 210424, "location": "tabriz", "created_at": "2017-05-09 01:39:44", "updated_at": "2017-05-16 17:19:28", }

Undefined property: Illuminate\Database\Eloquent\Builder

ぃ、小莉子 提交于 2019-12-24 05:53:00
问题 This strange thing is happening to me.I have the code below : $state_image =States_Images::where('id_state', $id); echo $delete_path=$state_image->name; and the result is : Undefined property: Illuminate\Database\Eloquent\Builder::$name Someone help me pls :( 回答1: You need to finish the query with get() or first(). In your case probably: States_Images::where('id_state', $id)->first(); 来源: https://stackoverflow.com/questions/37144564/undefined-property-illuminate-database-eloquent-builder

Laravel 5.1 Multitenancy setup

冷暖自知 提交于 2019-12-24 05:22:08
问题 I am using Laravel 5.1 and have a multi-tenancy database setup using a trait and scope as below. How can I add to this so that all insert queries also get the cust_id parameter injected? Scope: <?php namespace App\Scopes; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\ScopeInterface; use App\Customers; use DB, Session; class MultiTenantScope implements ScopeInterface { /** * Create a new filter instance. * * @param UsersRoles

Passing parameter in Eloquent ORM inside a javascript function

∥☆過路亽.° 提交于 2019-12-24 05:21:50
问题 I have a Laravel app where i'm using jQuery DataTables Master/Details to show some extra information. I can show the data to the child row, but I want it filtered first, depending on the row selected. The information that i want to retrieve is not on the original data source which I used to create the DataTable. Therefore i want to pass the record id to the new query that I am using directly from the javascript. Here is the code: function kpi_values(d) { // `d` is the original data object for

Laravel Eloquent ->with() and ->select() conflict with each other

故事扮演 提交于 2019-12-24 04:29:06
问题 Consider this code: Articles ::select('article_id', 'article_text') //This one does not work as expected ->with([ 'user' => function($q){ $q->select('user_id', 'user_name'); // This one works fine } ]) ->get(); When building query in Eloquent, we can use ->with() to retreive associated models. We can also attach ->select(), to determine which columns should be selected from associated model. However, looks like we loose possibility to specify which columns should be selected from the base

Update Database using Laravel Schedule Cronjob

半世苍凉 提交于 2019-12-24 04:26:05
问题 I am trying to run an Eloquent model to insert data to the database, I tried to run a test run using Laravel schedule and cronjobs, below is my code This is my App\Console\kernel.php protected $commands = [ 'App\Console\Commands\test', ]; /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->command('check:test')->everyMinute(); } And my App\Console\Commands

Laravel5: How are Eloquent model relationships expressed in the database?

廉价感情. 提交于 2019-12-24 04:08:09
问题 There's a missing link I fail to understand. I use migrations to create database tables and I define the relationships there. meaning.. if I have a person table and a job table and I need a one to many relationship between the person and jobs, I'd have the job table contain a "person_id". When I seed data or add it in my app, I do all the work of adding the records setting the *_id = values etc. but somehow I feel Laravel has a better way of doing this. if I define that one to many

Custom soft delete column and value for Eloquent ORM

我与影子孤独终老i 提交于 2019-12-24 03:52:45
问题 I'm in the process of rewriting a REST service, and I've decided to go with Slim Framework and I'm using Eloquent ORM because it works best for me. Previously I have done my soft deletes with a column deleted and set it to either 1 or 0 for deleted or not. With Eloquent it sets a timsestamp to a column deleted_at , is there a way I can set it to my previous soft delete method of just setting deleted to 1? 来源: https://stackoverflow.com/questions/27910953/custom-soft-delete-column-and-value-for