Category : database

For example I have online store with keyboards and mouses tables. And on the product(keyboard or mouse) page I want to show Recommended to buy with… section where other product (keyboard or mouse) will appear. So on Keyboard#1 page may be recommended Keyboard#2 and Mouse#1, that means on Keyboard#2 and Mouse#1 pages will be recommended ..

Read more

how to loop the data from database my route in laravel is Route::get(‘api/contacts’, [ContactController::class, ‘index’])->name(‘contact.index’); and im trying to display all the list but im confuse with the js code someone expert here and please help me class ContactController extends Controller { /** * Display a listing of the resource. * * @return IlluminateHttpResponse */ ..

Read more

I need your suggestion for this morph one to one table name. This for comic information. there’re 3 information, i need to split to different table. cause it additional information for specific media type ( comic, movie, tv show ). each type media will have different additional information i need to split. i think its ..

Read more

I have an HTML section that tagged with ID below: <section id="contactus" style="background-color: #fff"> it is a Contact Us From that will send emails to admin but i want the route to go back to this section after submitting the form this is the Route: Route::get(‘/’, [ContactUsFormController::class, ‘createForm’]); Route::post(‘/’, [ContactUsFormController::class, ‘ContactUsForm’])->name(‘contact.store’); so ‘/’ is my ..

Read more

Is there possibility to get whole database’s table with it’s associates? My example class Gambler extends Model { use HasFactory; public function horse() { return $this->belongsTo(Horse::class, ‘horse_id’, ‘id’); } } I am fetching data of Gamblers with axios, wich is being returned with this code in controller public function getGamblers () { echo Gambler::all(); } ..

Read more

Laravel Migration One of my table have grater then 250 columns. When I run migration its showing Syntax error or access violation: 1118 Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. In local system I have resolved this error by editing file – nano /etc/mysql/my.cnf ..

Read more

I want to remove data if AB and BA is the same This is my code: DB::table(DB::raw(‘tenant_db.sales_data as b’)) ->selectRaw(‘a.product_id as product_id, b.product_id as bought_with, count(*) as times_bought_together’) ->leftJoin(DB::raw(‘tenant_db.sales_data as a’), function ($join){ $join->on(‘a.sale_id’, ‘=’, ‘b.sale_id’); $join->on(‘a.product_id’, ‘<>’, ‘b.product_id’); }) ->havingRaw(‘SUM(a.qty) >= SUM(b.qty)’) ->groupBy(‘a.product_id’, ‘b.product_id’) ->orderBy(‘times_bought_together’, ‘DESC’) ->get(); I want the most bought item on ..

Read more

This query works with group by $data = DB::select(DB::raw("SELECT SUM(pending) as total , datediff(NOW(), created_at) as maturity FROM `admin_case_info` WHERE deleted_at is NULL group by maturity ")); But when I joined 2 tables. $data = DB::select( DB::raw("SELECT admin_case_info.case_type, admin_case_info.case_status, SUM(admin_case_info.pending) as total, datediff(NOW(), admin_case_info.created_at) as maturity FROM admin_case_info JOIN users_mws on users_mws.id = admin_case_info.users_mws_id JOIN ..

Read more

Want to remove duplicate data based on Quantity, DB::table(DB::raw(‘tenant_db.sales_data as b’)) ->selectRaw(‘a.product_id as product_id, b.product_id as bought_with, count(*) as times_bought_together, SUM(a.qty) AS aQuantity, SUM(b.qty) AS bQuantity’) ->join(DB::raw(‘tenant_db.sales_data as a’), function ($join){ $join->on(‘a.sale_id’, ‘=’, ‘b.sale_id’); $join->on(‘a.product_id’, ‘<>’, ‘b.product_id’); }) ->groupBy(‘a.product_id’, ‘b.product_id’) ->orderBy(‘times_bought_together’, ‘DESC’) ->get(); Something like this ->having(‘aQuantity’, ‘>’, ‘bQuantity’) Result that I get 0 => ..

Read more

Expect: select robotid, number from tool where is_active = 1 select * from robot_team where id = robotid( robotid from tool) foreach id(from robot_team), number(from tool) , status_za(from robot_team), status_zb(from robot_team), status_zm(from robot_team), status_qs(from robot_team) Result: cannot show success through postman Code: public function robotStatus() { $arr=[]; $robotlist = DB::table(‘robot_team AS u’) ->Join(DB::connection(‘sql’)->table(‘tool AS m’), ..

Read more

The data for one of my relationships should or should not be displayed based on a condition based on the item I’m trying to retrieve. personDecodedId = Hashids::decode($perrson_id)[0]; $person = Person::where(‘id’, $personDecodedId) ->withMediaAndVariants([‘avatar’]) ->with([‘person_feeds’ => function($query) { $query->withMediaAndVariants([‘children-image’, ‘feed-avatar’, ‘transaction’]) ->orderBy(‘created_at’, ‘DESC’); }, ‘team.owner’, ‘order’, ‘order.contacts’]) ->first(); My person_feeds relation contains a boolean field named ..

Read more