Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - Migrations 'Blueprint' meaning?

I need a bit of advice.

I have a few migrations files in my setup.

In some of them im seeing the following code which arent in the rest and im not sure what its for

use Illuminate\Database\Schema\Blueprint;
Schema::create('brand', function(Blueprint $table)

Could anyone tell me what the blueprint lines are for? as they arent in the other create table migrations.

Thanks

like image 420
BigJobbies Avatar asked Aug 08 '13 10:08

BigJobbies


People also ask

What is Blueprint in migration Laravel?

Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human-readable definition. Blueprint works by using a draft file (YAML) that contains definitions of the components it should generate.

What is the purpose of Laravel migration?

Laravel Migrations allow developers to programmatically create, update, and destroy database tables, working as a version control system for your database schema.

What is migration file explain it in brief with example in Laravel?

What is Laravel Migration? Laravel Migration is an essential feature in Laravel that allows you to create a table in your database. It allows you to modify and share the application's database schema. You can modify the table by adding a new column or deleting an existing column.

Should I use migration in Laravel?

In Laravel, Migration provides a way for easily sharing the schema of the database. It also makes the modification of the schema much easier. It is like creating a schema once and then sharing it many times.


1 Answers

This is because in your closure the parameter $table is tagged to be a Blueprint object. In fact every time a Blueprint is passed into the closure of Schema::create. So you can restrict the parameter to Blueprint then PHP throws an fatal if an object of an other type is passed, or you can leave it blank so that PHP doesn't check the passed object.

Just look up the files where the use-Statement is missing. There will be no parameter constraint.

like image 145
Jan P. Avatar answered Sep 25 '22 08:09

Jan P.