laravel-eloquent

Why wheredate not working in laravel 5.3?

十年热恋 提交于 2019-12-02 07:59:17
My laravel eloquent is like this : public function search(Request $request) { $search = ''; $searchdate = '2017-04-27'; $reports = Report::whereHas('user', function($query) use ($search) { $query->where(function ($q) use($search) { $q->where('name' ,'LIKE' ,'%'.$search.'%'); }); })->orWhereHas('store', function($query) use ($search){ $query->where(function ($q) use($search) { $q->where('name', 'LIKE', '%'.$search.'%'); }); })->orWhereHas('category', function($query) use ($search) { $query->where(function ($q) use($search) { $q->where('name', 'LIKE' , '%'.$search.'%'); }); })->whereDate(

Laravel (HasMany) doesnt rectrieve values

微笑、不失礼 提交于 2019-12-01 23:52:37
I have the following models: namespace App; use Illuminate\Database\Eloquent\Model; class forum_category extends Model { // protected $table = 'forum_category'; public function posts() { $this->hasMany('App\forum_post'); } } And namespace App; use Illuminate\Database\Eloquent\Model; class forum_post extends Model { // protected $table = 'forum_post'; public function category() { $this->belongsTo('App\forum_category'); } } in my controller i attempt to get all categories with their posts: namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use App

Distinct most recent data from database

故事扮演 提交于 2019-12-01 21:54:32
I am storing data in my database. The data being stored looks like this id | upload_month | created_at ----------------------------------------- 1 | January | 2017-01-30 13:22:39 ----------------------------------------- 2 | Febuary | 2017-01-30 13:23:42 ----------------------------------------- 3 | January | 2017-01-30 13:25:33 Within my Controller I am trying to retrieve the distinct upload_month, but get the latest inserted version for each. At the moment I am trying $uploadedFile = UploadedFile::groupBy('upload_month')->orderBy('created_at', 'desc')->get(); The problem is that this is

auto-injected Laravel model has no attributes

爷,独闯天下 提交于 2019-12-01 20:09:01
问题 I'm new to Laravel. I have created a model, a resource controller, and a route for one of my tables, I have modified the model class to use a particular table name, but the model object injected by Laravel 5.4 has no attributes even though a corresponding record exists in the database. Here are the steps I took. 1) Create the model with artisan. I ran this command: php artisan make:model Tree 2) Modify the Tree model class as instructed to specify a specific table. I had to do this because my

auto-injected Laravel model has no attributes

*爱你&永不变心* 提交于 2019-12-01 19:03:34
I'm new to Laravel. I have created a model, a resource controller, and a route for one of my tables, I have modified the model class to use a particular table name, but the model object injected by Laravel 5.4 has no attributes even though a corresponding record exists in the database. Here are the steps I took. 1) Create the model with artisan. I ran this command: php artisan make:model Tree 2) Modify the Tree model class as instructed to specify a specific table. I had to do this because my table is named tree , not the "trees" as Laravel would otherwise assume based on its internal rules. /

How to select columns from joined tables: laravel eloquent

♀尐吖头ヾ 提交于 2019-12-01 04:08:33
问题 I have a different problem from this. The scenario is same but I am in need of more filtration of the results. Let me explain. Consider I have 2 tables vehicles id name staff_id distance mileage staffs id name designation I want to select only id and name from both tables(Models). The Vehicle Model contain a belongsTo relation to Staff model. class Vehicle extends Model { public function staff() { return $this->belongsTo('App\Staff','staff_id'); } } and I joined using this Vehicle::where('id'

How can I update pivot table on laravel?

被刻印的时光 ゝ 提交于 2019-11-29 18:10:34
I use laravel 5.3 I have 3 table : table product, table category and table products_categories table product : id, name, etc table category : id, name, etc table products_categories : id, product_id, category_id In model product, I have method this : public function categories() { return $this->belongsToMany(Category::class, 'products_categories', 'product_id', 'category_id') ->withPivot('id') ->withTimestamps(); } So 1 product have many category My code like this For example $param['category'] like this : Array ( ['category1'] => 4 ['category2'] => 11 ['category3'] => 18 ) $product_id = 1

Laravel - seeding large SQL file

倖福魔咒の 提交于 2019-11-29 02:08:54
A memory exhaustion happens when I run my DB seed script in production. Below is my seed script. class MembershipTableSeeder extends Seeder { public function run() { DB::table('members')->delete(); foreach (range(1, 99) as $days){ Members::create(array('membership_code' => 'test'.$days)); } DB::unprepared(file_get_contents(app_path()."/database/seeds/members.sql")); } } So what I did was add a no-limit on my seed script. ini_set('memory_limit', '-1'); The problem now is that when I run the script it logs the output into the terminal the content of the SQL script (which is very, very big). Is

How to solve Missing argument 1 for App\\Repositories\\FavoriteRepository::delete() ? (Laravel 5.3)

我怕爱的太早我们不能终老 提交于 2019-11-28 02:24:47
My service is like this : public function delete($store_id) { $result = $this->favorite_repository->delete($store_id); dd($result); } My repository is like this : public function delete($store_id) { $data = self::where('favoritable_id', $store_id)->delete(); return $data; } There exist error : Missing argument 1 for App\Repositories\FavoriteRepository::delete(), called in C:\xampp\htdocs\mysystem\app\Repositories\FavoriteRepository.php on line 45 and defined Can you help me? UPDATE The delete function in the EloquentRepository is like this : public function delete($id) { // Find the given

Laravel - seeding large SQL file

不想你离开。 提交于 2019-11-27 16:27:55
问题 A memory exhaustion happens when I run my DB seed script in production. Below is my seed script. class MembershipTableSeeder extends Seeder { public function run() { DB::table('members')->delete(); foreach (range(1, 99) as $days){ Members::create(array('membership_code' => 'test'.$days)); } DB::unprepared(file_get_contents(app_path()."/database/seeds/members.sql")); } } So what I did was add a no-limit on my seed script. ini_set('memory_limit', '-1'); The problem now is that when I run the