Posts in: Laravel

Ajax not working in Laravel?

0 comments / June 29, 2019

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

0 comments / May 14, 2019

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 createRead more

Create database for branch and phpunit

0 comments / April 24, 2019

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

Pivot tables don’t need an AI column

0 comments / December 8, 2018

Most scenarios are covered by a hasOne, hasMany or ManyToMany relation. How to use them is explained in detail here. I give a brief overview how they are connected to the database. User hasOne Phone You should have two tables that look somehow like this: From the user class you can access his phone asRead more