Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Laravel eloquent relationships


In laravel you can define all kind of relationships between database tables on the model itself (as in laravel, model is representation of database table), so here's list of eloquent relationships that you can use in laravel model.

Insert using DB table doesnt update timestamp


In laravel there are two ways to insert data/record, using DB table or using model, but i found a problem when inserting the data using DB table, the timestamp created_at and updated_at is showing '0000-00-00 00:00:00' as value.

How to add primary key to Laravel model?


If you did not specify primary key in your model, laravel will assume the primary key of the table is 'id', so for example your primary key is not 'id', but let's say 'user_id' or 'employee_id' etc, how to define this in the model?

php artisan migrate command in Laravel


The 'php artisan migrate' command lets you run the database migration on your application, but there is more than that, there are other variant of this command that you can use such as rollback, reset, refresh, status, install and so on.

How to add and drop indexes in Laravel schema builder


On your laravel database migration you can define indexes for each table that you create, for example you can add primary key, unique value, or just a basic index. All can be done in laravel schema builder.

How to check table column exist or not in Laravel


Besides the 'hasTable' static method, you also have 'hasColumn' method which can check column exist or not on database table of laravel.

How to check table exist or not in Laravel


Is it possible to check existence of database table in laravel code? the answer is yes, it is possible to check whether a table already exist or not in laravel.

Laravel 4.2 schema table column types


These are list of schema table column types that you can use when creating database migration on laravel 4.2, most of these column types also available on laravel 5, this post is just for quick reference.

How to exit from php artisan tinker


Some people having difficulty closing/exit from artisan tinker mode, this is also happened to me when i use artisan tinker for the first time, i don't know how to close it.

Interact with your application using artisan tinker


Another cool feature in laravel is the ability to interact with your application via artisan tinker, using artisan tinker you can execute php code and interact with your application code.

How to check Eloquent get() and first() query result


Every time you run query to the database whether using eloquent get() or first() method, it's always a good idea to check the result of the query before doing other things, make sure the result is as we expected and not returning empty.

How to create table seeder in Laravel 4.2


Seeding is the technique of filling our database with sample data so we can test and create our applications. It really does make building applications much easier.

Echoing data with default value in Laravel blade


When echoing data in laravel blade template using double or triple curly braces, you don't need to worry if the value is empty, it will not displayed as an error, but sometimes you want to put a default value if the data is empty.

What is forelse loops in Laravel blade?


Besides 'foreach' loops, we also got 'forelse' loops in laravel blade template, what exactly this 'forelse' loops does? and most importantly should we care about it?

Looping in Laravel blade template


Just like the 'if' statement, blade also has it's own way of doing loops/looping, you can do 'for' loops, 'foreach', 'forelse', and also 'while' loops. Let's take a look at the syntax.

If statement in Laravel blade template


Blade template have it's own way of doing conditional 'if' statement, the syntax is little bit different from the regular php 'if' statement, but works the same way.

How to escape output in Laravel blade


When you use the blade template in laravel, specially laravel version 4, if you use the double curly braces to output something, then you are vulnerable to XSS exploits, you need to escape the output.

Category

Category