Category : eloquent

I have three Models. University, Professor and Student. They have some relations. University Model : <?php namespace AppModels; use IlluminateDatabaseEloquentModel; use AppModelsUser; class University extends Model { protected $fillable = [‘name’, ‘user_id’]; /** * Get the user that owns the university. */ public function owner() { return $this->belongsTo(User::class); } } Professor Model : <?php namespace ..

Read more

I try to do : php artisan make:model Lala -m but I receive the following line: **Model created successfully.** Created Migration: 2021_11_27_225646_create_lalas_table **SymfonyComponentProcessExceptionRuntimeException** A temporary file could not be opened to write the process output: fopen(C:UsersCARINE~1AppDataLocalTempsf_proc_00.out.lock): failed to open stream: Permission denied at C:laragonwwwwebappvendorsymfonyprocessPipesWindowsPipes.php:63 59▕ if (file_exists($file.’.lock’)) { 60▕ continue 2; 61▕ } 62▕ restore_error_handler(); ..

Read more

I have a situation where I need to validate an identification number in two different tables (companies and units). The company can register the units it owns, but the system cannot allow the identification code to be duplicated in the tables (companies and units). A typical validation would look like this: Store unique:companies,cnpj Update unique:companies,cnpj,{$this->company->id} ..

Read more

i want to get al product attributes (if any) for the given product id using a sub query in join. Below is my query $product_attributes = ProductAttributes::select(‘name as attribute_name’, ‘value as attribute_value’)->get(); $data[‘product’]= Product::select(‘products.*’,’vendors.name as vendor_name’,’product_discounts.start_time’, ‘product_discounts.end_time’, ‘product_discounts.discount_type’,’product_discounts.discount_value’,’product_attributes.name’,’product_attributes.value’) ->leftjoin(‘product_discounts’,’products.id’,’=’,’product_discounts.product_id’) ->joinSub($product_attributes, ‘product_attributes’, function ($join) { $join->on(‘products.id’, ‘=’, ‘product_attributes.product_id’); })->leftjoin(‘vendors’,’products.vendor_id’,’=’,’vendors.id’)->where(‘id’,$request->product_id)->first(); This query gives me following error InvalidArgumentException ..

Read more

I want to make email_verified_at null and send confirmation email if user updated their email. And after reading some tutorial on Internet I found something called boot function. But somehow my boot function in my User model is not fired. Model User.php class User extends Authenticatable implements MustVerifyEmail { use Notifiable; protected static function boot() ..

Read more

I got this error when I started my laravel project today IlluminateDatabaseQueryException SQLSTATE[HY000]: General error: 2 Error reading file ‘.faorganizations.frm’ (Errcode: 13 "Permission denied") (SQL: select * from ‘organizations’ order by ‘created_at’ asc). At first I’m getting an execution time error of 60 seconds, then when I refresh the page, I got this error. Does ..

Read more

I am adding a search form to my laravel application and I have a problem. Please help me. Here is the html form: <form action="{{ route(‘Test.search’)}}" method="GET" > {{csrf_field()}} <input type="text" name="name" > <input type="submit" value="send"> </form> this is the road: Route::get(‘/search’,[ ‘as’ =>’Test.search’, ‘uses’ =>’[email protected]’]); method search: public function search() { $sea=$_GET[‘name’]; $b2= Test::where(‘name’, ..

Read more

I have two models (Owner and Car), with an one to one relationship between them. Both models use soft deletes. If either model is soft deleted, it should soft delete it’s relation. Currently, when Owner is deleted, I use events to delete Car: App/Models/Owner protected static function booted() { static::deleted(function ($owner) { $owner->car->delete(); }); static::restored(function ..

Read more

I have a requirement. My DB has tables like the following. The tables have OneToMany (1-n) parent-child relation. Table School (id, school_name) Table Class (id, school_id, class_name) Table Section (id, class_id, section, no_of_seats) Table Student (id, section_id, student_name, ….) When Some Student is registered, data is uploaded to the Student table. Now, I want to ..

Read more

I have a requirement. My DB has tables like the following. The tables have OneToMany (1-n) parent-child relation. Table School (id, school_name) Table Class (id, school_id, class_name) Table Section (id, class_id, section, no_of_seats) Table Student (id, section_id, student_name, ….) When Some Student is registered, data is uploaded to the Student table. Now, I want to ..

Read more

I’m using different allies for morph Relations with morphMap(). When I use WhereHasMorph() and give my custom morph type, it doesn’t work. in Controller : $data = Product::whereHasMorph( ‘productable’, [‘PrintedBook’], // Book::class function (Builder $query, $type) use($title){ $query->where(‘title’, ‘LIKE’, "WhereHasMorph query doesn’t work with custom morph types%"); } )->get(); and in Book model : public ..

Read more

I have a dilemma with my system, I have 2 controllers: patients and histories and I would like that when creating a history it would bring me the patient’s data and when saving that history the patient data with the history data is saved, someone help me use LARAVEL 8 migration table class CreateHistorialsTable extends ..

Read more