Controller Statements
Blueprint comes with an expressive set of statements which define code within each controller action, but also additional components to generate.
Each statement is a key: value
pair.
The key
defines the type of statement to generate. Currently, Blueprint supports the following types of statements: delete
, dispatch
, find
, fire
, flash
, notify
, query
, redirect
, render
, resource
, respond
, save
, send
, store
, update
, validate
.
delete
Generates an Eloquent statement for deleting a model. Blueprint uses the controller action to infer which statement to generate.
For example, within a destroy
controller action, Blueprint will generate a $model->delete()
statement. Otherwise, a Model::destroy()
statement will be generated.
dispatch
Generates a statement to dispatch a Job using the value
to instantiate an object and pass any data.
For example:
dispatch: SyncMedia with:post
If the referenced job class does not exist, Blueprint will create one using any data to define properties and a __construct
method which assigns them.
find
Generates an Eloquent find
statement. If the value
provided is a qualified reference, Blueprint will expand the reference to determine the model. Otherwise, Blueprint will attempt to use the controller to determine the related model.
fire
Generates a statement to dispatch a Event using the value
to instantiate the object and pass any data.
For example:
fire: NewPost with:post
If the referenced event class does not exist, Blueprint will create one using any data to define properties and a __construct
method which assigns them.
flash
Generates a statement to flash data to the session. Blueprint will use the value
as the session key and expands the reference as the session value.
For example:
flash: post.title
notify
Generates a statement to send a Notification using the value
to instantiate the object, specify the recipient, and pass any data.
For example:
notify: post.author ReviewPost with:post
If the referenced notification class does not exist, Blueprint will create one using any data to define properties and a __construct
method which assigns them.
You may also send a notification using the Notifiable
trait by passing a model reference.
For example:
notify: user AccountAlert
query
Generates an Eloquent query statement using key:value
pairs provided in value
. Keys may be any of the basic query builder methods for where
clauses and ordering.
For example:
query: where:title where:content order:published_at limit:5
Currently, Blueprint supports generating query statements for all
, get
, pluck
, and count
.
redirect
Generates a return redirect()
statement using the value
as a reference to a named route passing any data parameters.
For example:
redirect: post.show with:post
render
Generates a return view();
statement for the referenced template with any additional view data as a comma separated list.
For example:
render: post.show with:post,foo,bar
When the template does not exist, Blueprint will generate the Blade template for the view.
resource
Generates response statement for the Resource to the referenced model. You may prefix the plural model reference with collection
or paginate
to return a resource collection or paginated collection, respectively.
If the resource for the referenced model does not exist, Blueprint will create one using the model definition.
For example:
resource: user
resource: paginate:users
respond
Generates a response which returns the given value. If the value is an integer, Blueprint will generate the proper response()
statement using the value as the status code. Otherwise, the value will be used as the name of the variable to return.
For example:
respond: post.show with:post
When the template does not exist, Blueprint will generate the Blade template for the view.
save
Generates an Eloquent statement for saving a model. Blueprint uses the controller action to infer which statement to generate.
For example, for a store
controller action, Blueprint will generate a Model::create()
statement. Otherwise, a $model->save()
statement will be generated.
send
Generates a statement to send a Mailable or Notification using the value
to instantiate the object, specify the recipient, and pass any data.
For example:
send: ReviewPost to:post.author with:post
If the referenced mailable class does not exist, Blueprint will create one using any data to define properties and a __construct
method which assigns them.
store
Generates a statement to store data to the session. Blueprint will slugify the value
as the session key and expands the reference as the session value.
For example:
store: post.title
Generates:
$request->session()->put('post-title', $post->title);
update
Generates an Eloquent update
statement for a model. You may use a value of the model reference to generate a generic update
statement, or a comma separated list of column names to update.
For example:
update: post
update: title, content, author_id
When used with a resource controller, Blueprint will infer the model reference.
validate
Generates a form request with rules based on the referenced model definition. You may use a value of the model reference to validate all columns, or a comma separated list of the column names to validate.
For example:
validate: post
validate: title, content, author_id
Blueprint also updates the type-hint of the injected request object, as well as any PHPDoc reference.