I have this working code with AS count self declared field using eloquent $delimeter = ‘ ‘; $keywords = explode($delimeter, $keyword_search); $base_query = DB::table(‘yeast_entire_search’)->selectRaw(‘ id, part_number, part_name, Round ((Char_length(Concat( LOWER(part_number), LOWER(part_name) )) – Char_length(REPLACE ( Concat( LOWER(part_number), LOWER(part_name) ), LOWER("’.$keyword_search.’"), ""))) / Char_length(LOWER("’.$keyword_search.’"))) AS count ‘); foreach($keywords as $keyword){ $base_query->where(function($query) use ($keyword){ $query->where(‘part_number’, ‘like’, ‘%’ ..
Category : eloquent
I would like to save the following object to a field on a mongodb collection via eloquent "project_settings" : { "resource" : true, "zone" : true, "contractor" : true, "responsible_person" : false } this is my php code: return ProjectModel::where($project_id)->first()->update($project_data); dont worry about the model it works fine i need to make a query that ..

I have a MySQL in the following format. I want to duplicate the entries in this table[products] [filtered by event_id] to another table [user_products]. What is the best approach to do this? In the user_products table while inserting the records, i will also have to add a user_id which gets passed to the code from ..
I am new to laravel and building my first project using it. I want to query two tables (Cases and Detail) using orWhere() function. Please tell me the changes I need to make in my existing code. Controller.php $key = trim($request->get(‘q’)); $cases = Cases::query() ->where(‘cnic’, "$key") ->orWhere(‘eventDate’, "$key") ->get(); return view(‘adminHome’,[‘user’ => $cases ]); The ..
? Hi! Sorry the title isn’t that explicite, but I’m a beginner and I really don’t have the vocabulary just yet ? I’ve been struggling for hours with something, so before I trow my computer by the window, I came to ask for help :3 In my database I have a table with exhibitors and ..
I am having those two table Schemas (Client and Product Models) with a One to Many relationship. I am using mysql database. Schema::create(‘clients’, function (Blueprint $table) { $table->id(); $table->string(‘name’); $table->string(‘job’); $table->timestamps(); }); Schema::create(‘products’, function (Blueprint $table) { $table->id(); $table->foreignId(‘client_id’)->constrained(); $table->string(‘productName’)->unique(); $table->integer(‘quantity’); $table->float(‘unitPrice’); $table->timestamps(); }); I also tried to use the syntax below instead of $table->foreignId(‘client_id’)->constrained(); ..

I do my migration with some normal data, and the data end up in my database without any issue. Then I use postman to test my POST method, with exactly the same data but it craches the server Error 500. I checked line by line and find that it happens when I do $log->save(); in ..
This question is very similar to [1]. Sorry, if it turns out as a duplicate later on, but I have another working code to provide. What does work is filtering on the client side via JavaScript: filterfunction : function(entry, filter) { let retVal = true; if(filter != null) { let localfilter = filter.trim().split(‘ ‘); // ..
With Laravel, I have this kind of structure in a json db column : [ { "shift": "2", "users[]": [ "2657" ], "products[]": [ "SKU1" ], "users_categories[]": [ "CATEGORY1" ], "products_categories[]": [ "13" ] }, { "shift": "4", "users[]": [], "products[]": [], "users_categories[]": [ "CATEGORY1", "CATEGORY2", "CATEGORY3", "CATEGORY4" ], "products_categories[]": [] } ] How can ..
$products = product::select([ DB::raw(‘product_no as number’), DB::raw(‘product_name as name’), DB::raw(‘sum(total) as total’), DB::raw(‘sum(product_qty) as qty’), DB::raw(‘sum(product_price) as price’), ]) ->groupBy(‘number’) ->groupBy(‘name’) ->get(); return view (‘view’,[‘products’=>$products]); i need to insert the result to another table in database by laravel Sourc..
i´m traying to do query into my repository to get galleries that to have a restaurant and i need seach for id. One restaurant´s gallery only can to have 10 images, but we can to have more than one restaurant. I need that when one restaurant will have a 10 images, it can´t upload any ..
Let’s assume that I have 2 tables: Users: Schema::create(‘users’, function (Blueprint $table) { $table->increments(‘id’); $table->string(‘name’); $table->string(’email’)->unique(); $table->integer(‘age’) $table->string(‘password’); $table->rememberToken(); $table->timestamps(); }); Phones: Schema::create(‘phones’, function (Blueprint $table) { $table->increments(‘id’); $table->integer(‘user_id’)->unsigned(); $table->string(‘phone’); $table->timestamps(); $table->foreign(‘user_id’)->references(‘id’)->on(‘users’) ->onDelete(‘cascade’); }); User Model: public function phone() { return $this->hasOne(‘AppPhone’); } Phone Model: public function user() { return $this->belongsTo(‘AppUser’); } When I perform ..
I’m stuck on this point: I got some migrations like this: <?php Schema::create(‘product_categories’, function ( $table) { $table->bigIncrements(‘id’); $table->timestamps(); }); Schema::create(‘products’, function ( $table) { $table->bigIncrements(‘id’); $table->unsignedBigInteger(‘category_id’)->nullable(); $table->foreign(‘category_id’)->references(‘id’)->on(‘product_categories’)->onDelete(‘cascade’); }); This results in: CREATE TABLE `product` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `category_id` bigint(20) unsigned DEFAULT NULL, PRIMARY KEY (`id`), KEY `product_category_id_foreign` (`category_id`), CONSTRAINT `product_category_id_foreign` ..

I am using maatwebsite to export the records to CSV file. Using php laravel for backend. Here is my following code: Controller code: public static function exportCsvReport($params){ header(‘Content-Encoding: UTF-8’); header(‘Content-type: text/csv; charset=UTF-8’); return Excel::download(new UsersExport, ‘invoices.xlsx’); } UserExport model: <?php namespace AppExports; use AppModelsApiv1Tbcall; use MaatwebsiteExcelConcernsFromCollection; class UsersExport implements FromCollection { public function collection() { ..
I have two models in laravel with a OneToOne relation, Team and Venue. I’m trying to populate both tables, but each one needs the id as a foreign key of the other table from another model. For example, if I want to create a Venue, I need the Team id, but it doesn’t exist yet. ..
I have two models using different tables on two different connections, User and UserInfo. User has a UserInfo hasMany relation: public function userInfo() { return $this->hasMany(‘pathtoUserInfo’,’User_ID’); } and UserInfo has a User belongsTo relation: public function user() { return $this->belongsTo(‘anotherpathtoUser’, ‘User_ID’, ‘User_ID’); } I would like to find the first user with more than one ..
I am using Laravel 8, and I need to validate a user using data from 2 tables: users and customers. When user logs in, they will input 3 values: email, password and account. "Account" field comes from customer table. So I need to do a join to access "account" field from "customers" table. One option ..
I just learned laravel web programming about 2 weeks ago I have 2 tables, namely anggotas and simpanans which has one-to-many relationship one anggota (id_anggota as pk) can have many simpanan(id simpanan as pk) I use id_anggota as a foreign key in the simpanans table when I delete one of the data in the simpanans ..
I have eloquent relationships with category child In category Model public function products() { return $this->hasMany(Products::class, ‘category’, ‘id’); } public function sub() { return $this->hasMany(SELF::class, ‘parent_id’)->withCount([‘products’])->with(‘sub’); } I would like to get in each category and child category has products count Example Category A is the parent Category B and C are child of A ..
I need to convert this query form PostgreSQL in Eloquent but I failed: select invoice_item_id from ( select invoice_item_id, status, row_number() over (partition by invoice_item_id order by id) as rank, lead(invoice_item_id) over (partition by invoice_item_id) as next from payment_invoice_item_status as piis where invoice_item_id > 6000000 and status in (3191,3238) )d where status=3191 and rank=1 and ..
i’m using laravel 7.30, I have a post model linked to user model with belongsTo relationship, I want to retrieve all posts with user property that contains only the name of the user for api purposes. what i’ve tried so far. public function index() { return Post::with(‘user:id,name’)->get(); } but the result of this code is ..
I have this Controller called GetChangeInfo public function GetChangeInfo(Request $request){ $customers = Customer::doesntHave(‘bookings’) ->doesntHave(‘product_baskets’) ->whereRaw("CONCAT(customers.id, COALESCE(customers.first_name, ”), ‘ ‘, COALESCE(customers.last_name, ”), ‘ ‘, COALESCE(customers.email, ”), ‘ ‘, COALESCE(customers.phone, ”), ) LIKE ?", ["%{$request->find}%"] ) ->orderBy(‘id’, ‘desc’) ->paginate(10); return response()->json($customers); } I want to insert customers.pending_update_info, 1 this code inside in whereRaw whenever i insert that ..
All polymorh examples I found are one to many if I get it correct. (Tag to Post / Video e.g) In my Case the parent class is multiple and the child class also. Therefore i set up the pivot table Tables Person id Venture id Capital id Estate id PIVOT TABLE Revenues emitter_id //ID of ..
My delete function is not working. Instead it is redirecting to singleProduct page. What might be the error? Is there any mistake in delete form? I have one product listing page and that consists of edit button. When edit button is clicked it redirects to a form which contains update and delete button. When delete ..
1)When I tried to use Model in update function of controller I get the error? What might be the reason for it. I got error: Non-static method IlluminateDatabaseEloquentModel::update() should not be called statically 2)Another problem is that my delete function doesn’t delete the product. It redirects in another page. What might be the mistake in ..