Category : mysql

I have a User, who can create a membership. On the database, the membership has an expires_at, that I use on the frontend to display "Active" or "Inactive" depending on that time. I want some statistics. Newly created memberships are quite easy to handle, using the created_at field. When it comes to "active memberships", I’m ..

Read more

I am working on a Laravel project that uses several models with plural database names. In this example, the model: class RedCar extends Model Is supported by the table: red_cars I have another model called Dog that has a belongsToMany relationship: class Dog extends Model { public function red_cars() { return $this->belongsToMany(RedCar::class) ->select( array(‘name’,’description’) ); ..

Read more

I have wallets table like that: user_id amount currency 1 100 EUR 2 50 USD 2 200 AUD 1 120 EUR So I need something like that: User::select(‘users.*’, ‘wallets.amount’) ->leftJoin(‘wallets.amount as wallets.eur’, [[‘wallets.user_id’, ‘=’, ‘users.id’], [‘wallets.currency’, ‘=’, ‘eur’]]); ->leftJoin(‘wallets.amount as wallets.usd’, [[‘wallets.user_id’, ‘=’, ‘users.id’], [‘wallets.currency’, ‘=’, ‘usd’]]); To explain more, I need query which will ..

Read more

I’m sending this data to the view part that is written in view but isn’t displayed, do you think? $itemsCount = DB::table(‘items’) ->groupBy(‘level_id’) ->selectRaw(‘level_id, count(*) as type’); $ItemsMdCount = DB::table(‘items’) ->groupBy(‘project_model_id’) ->selectRaw(‘project_model_id, count(*) as type’); return view(‘project.view’, compact(‘users’, ‘itemsCount’, ‘itemsMdCount’)); And in vue I make the display {{ itemsCount }} How can I send the ..

Read more

Error Class ‘DatabaseFactoriesOpportuniyFactory’ not found at C:laravalforestvendorlaravelframeworksrcIlluminateDatabaseEloquentFactoriesFactory.php:650 646▕ public static function factoryForModel(string $modelName) 647▕ { 648▕ $factory = static::resolveFactoryName($modelName); 649▕ ➜ 650▕ return $factory::new(); 651▕ } 652▕ 653▕ /** 654▕ * Specify the callback that should be invoked to guess factory names based on dynamic relationship names. 1 C:laravalforestvendorlaravelframeworksrcIlluminateDatabaseEloquentFactoriesHasFactory.php:15 IlluminateDatabaseEloquentFactoriesFactory::factoryForModel("AppModelsOpportuniy") 2 C:laravalforestdatabaseseedersOpportunitySeeder.php:18 AppModelsOpportuniy::factory("AppModelsOpportuniy") [error shows ..

Read more

Can someone help me to convert this query into Laravel ELOQUENT? The query is below on the screenshot link and also on comment section DB::select(‘SELECT t1.* FROM messages AS t1 INNER JOIN ( SELECT LEAST(sender_id, receiver_id) AS sender_id, GREATEST(sender_id, receiver_id) AS receiver_id, MAX(id) AS max_id FROM messages GROUP BY LEAST(sender_id, receiver_id), GREATEST(sender_id, receiver_id) ) AS ..

Read more

I have a problem with a query. in posts table, i have posts.id, then, in reviews table, i have posts_id(foreign key -> posts.id), reviews.id. i want to query those posts_id which doesn’t exist in reviews table(post_id). i am using laravel query builders. i am trying like -> $r = DB::table(‘reviews’) ->select(DB::raw(‘count(id) as rev_count, posts_id’)) ->groupBy(‘posts_id’) ..

Read more

I would like to calculate the apartments in the project according to the floor. How could I do that? This is db table->id(); $table->unsignedBigInteger(‘project_building_id’)->nullable(); $table->unsignedBigInteger(‘project_model_id’); $table->string(‘apartment_number’)->nullable(); $table->unsignedBigInteger(‘level_id’)->nullable(); Leve_id is based on the floor But I would like that depending on project_model_id E.g: I have a 6-story building. Those 6 floors each assigned apartments. I would ..

Read more

Im new to laravel and I cant seem to download the pdf of my blade php file. Please help me out! Thank you! This is what I get If i click my "Export to PDF" button in my productlist.blade.php: ErrorException Undefined variable: products (View: C:xampphtdocslaravelproductcrudresourcesviewsproductlist.blade.php) This is my product controller file: <?php namespace AppHttpControllers; use ..

Read more

So me and a friend are working on a admin-view for user management. I wanted this view to option to be able to delete users by clicking a button. The userlist itself looks like this: @section(‘main’) @csrf <ul class="collapsible"> @foreach($users as $user) <li method="POST" action="delete"> <div class="collapsible-header"><i class="material-icons">face</i>{{$user->fname}} {{$user->lname}}</div> <div class="collapsible-body" id="{{$user->id}}"> <p>Adresse: {{$user->address1}}, {{$user->postalcode}} ..

Read more

Could someone help me with the following code please? I am using javascript to add a dynamic list using dropbox. In the first dropbox it works fine but in the second it only gives one item as shown enter image description here enter image description here <script type="text/javascript"> $(document).ready(function(){ var postURL = "<?php echo url(‘/admin/service/{{$cust_id}}’); ..

Read more

I am using eloquent where has relation in 3 global scopes and these scopes cause a significant performance drop this query takes about 140 seconds on the server to process!! this is the globalScopes protected static function boot() { parent::boot(); if ( !auth(‘admin’)->check() ) { static::addGlobalScope(new DoesntHaveForbiddenArtistScope()); static::addGlobalScope(‘has-artist’, function (Builder $builder) { $builder->whereHas(‘artists’); }); static::addGlobalScope(‘has-mp3’, ..

Read more

I want to know how can I write These two Eloquent Queries into raw SQL? also Is there a way to convert the Eloquent series into raw SQL series so that I could use those? public function items() { return $this->belongsToMany(Product::class, ‘order_items’, ‘order_id’, ‘product_id’)->withPivot(‘quantity’, ‘price’); } public function user() { return $this->belongsTo(User::class); } Sourc..

Read more