If you create a Laravel Package with Eloquent Models, then you probably want to test them.
Category Archives: Laravel
How to fix FPDF error: Undefined font
If you get this error, this could have one of the following causes 1. You forgot to set the font Before you set the font, its necessary to add the font! $pdf->AddFont(‘DejaVuSansCondensed’, ‘B’, ‘DejaVuSansCondensed-Bold.ttf’, true); $pdf->SetFont(‘DejaVuSansCondensed’, ‘B’, 11); 2. You forgot to set the fontpath Imagine you have specified some custom fonts then you need […]
Laravel: Sort by Relation
Imagine you have rows of different categories. This means each row belongs to a category and a category has many rows. Imagine you want to sort your categories by the latest row.
Load does not work for dynamical relationships?
Imagine you have the following two relations: /** * Relation working/holiday/.. hours * @return [type] [description] */ public function relatedHours($type = null) { $type = $type ?? $this->type; return $this->hours()->where(‘type’, ‘=’, $type); } public function workingHours() { return $this->relatedHours(Type::WORK); }
Send queued mails in Laravel with specific language
If you create a mailable class in Laravel, then you either create the content in the constructor, in the the blade or in both. If you want to send your mail in language X in queue then its relevant where the content is created at.
Ajax not working in Laravel?
Assume you have a list of items with checkboxes: <ul class=”project-ul”> @foreach ($projects as $project) <li> <label><input type=”checkbox” value=”1″ class=”checking” data-id=”{{$project->id}}” {{($project->featured) ? ‘checked’ : ”}}> {{$project->title}}</label></li> @endforeach </ul> This may return a list like this:
Foreign Keys in Laravel
Imagine you have a user who hasMany logs. If you delete the user, you probably don’t need the logs of him anymore. The cleanest way to automatically remove them is to use foreign keys in your database. Note that the foreign key column needs to be unsigned. Here is a clean code when you create […]
Best Practice For hasOne Relation in Laravel
User hasOne Phone You should have two tables that look somehow like this: From the user class you can access his phone as public function phone() { return $this->hasOne(‘App\Phone’); }
Create database for branch and phpunit
Whenever I work on a new branch, I find it useful to have a unique table for the branch and for my testing purposes. Lets assume we have three tables denoted in our `.env` file like that: DB_CONNECTION = mysql_local DB_DATABASE = mastertable DB_DATABASE_BRANCH = branchtable DB_DATABASE_TEST = testtable
How Null Works
Lets take a look at the following table (the quotation marks “…” only indicate that we have a string).