Category : eloquent

Categories table: $table->id(); $table->string(‘name’); $table->string(‘slug’)->unique(); $table->foreignId(‘parent_id’)->nullable(); $table->string(‘color’, 7)->default(‘#000000’); $table->timestamps(); $table->foreign(‘parent_id’) ->references(‘id’) ->on(‘categories’) ->onDelete(‘set null’); Categorizable table: $table->morphs("categorizable"); $table->foreignId(‘category_id’)->constrained()->onDelete(‘cascade’); $table->primary([‘categorizable_type’, ‘categorizable_id’, ‘category_id’], ‘categorizables_index’); Reviews table: $table->id(); $table->foreignId(‘user_id’)->constrained(); $table->string(‘title’); $table->string(‘seo_title’); $table->string(‘slug’)->unique(); $table->string(‘summary’); $table->longText(‘body’); $table->string(‘img’)->nullable(); $table->timestamps(); $table->timestamp(‘published_at’)->nullable(); Category model: public function reviews() { return $this->morphedByMany(Review::class, ‘categorizable’); } I’m using mysql 5.7. If I try to limit the reviews ..

Read more

I have two models products and image where product can have one or more image and image have one product related to and these are my models product model <?php namespace AppModels; use IlluminateDatabaseEloquentFactoriesHasFactory; use IlluminateDatabaseEloquentModel; use IlluminateDatabaseEloquentRelationsHasMany; use OwenItAuditingContractsAuditable; use OwenItAuditingAuditable as AuditableTrait; class Product extends Model implements Auditable { use HasFactory, AuditableTrait; /** ..

Read more

I have a table of items each with a status and a category. I’d like to produce an output page showing the number of items for each combination of status and category. I’m passing a collection of the applicable fields to the blade. Leaving out many other fields. $items = item::all(‘id’, ‘status_id’,’category_id’); Now in the ..

Read more

I’m trying to make a show view with Laravel 8 but i can’t show the detail, this is the code from the controller: public function show($id) { $accesorios=DB::table(‘accesorio as acc’) ->join(‘detalle_aparato as da’,’acc.idAccesorio’,’=’,’da.idAccesorio’) ->select(‘acc.Nombre’) ->where(‘da.idAparato’,’=’,$id); return view("almacen.aparato.show",["accesorio"=>Accesorio::findOrFail($id)]); } And this is the code from the view: @foreach ($accesorio as $acc) <tr> <td>{{ $acc->Nombre}}</td> </tr> @endforeach ..

Read more

I have setup Laravel Yajra datable backend package to handle the work for the ajax query calls to view via a jquery datatable. Everything worked great until I changed the eloquent query from: static function for_table($farm_ids) { return ChemProgramUser::select(‘chemprogramuser.id’, ‘chemprogramuser.farms_id as fid’, ‘chemprogramuser.description as head’, ‘chemprogramuser.hectares as ha’, ‘chemprogramapp.updated_at’, // this raw query caused the ..

Read more