Skip to content

Instantly share code, notes, and snippets.

@vertisan
Last active August 22, 2017 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vertisan/232de9bd88aa693acbae390435bb41f0 to your computer and use it in GitHub Desktop.
Save vertisan/232de9bd88aa693acbae390435bb41f0 to your computer and use it in GitHub Desktop.
Sublime Text 3 - Laravel Snippets (used PHP 7.1!)
<!-- Laravel Model - Custom connection -->
<snippet>
<content><![CDATA[
/**
* Connection type for model
* @var string
*/
protected \$connection = '${1:name_of_connection}';
]]></content>
<tabTrigger>laravel:connection</tabTrigger>
<tabTrigger>laravel:model:connection</tabTrigger>
<scope>source.php</scope>
</snippet>
<!-- Laravel Model - Fillable field -->
<snippet>
<content><![CDATA[
/**
* Field for mass-fill
* @var array
*/
protected $fillable = [
'${1:this}'
];
]]></content>
<tabTrigger>laravel:fillable</tabTrigger>
<tabTrigger>laravel:model:fillable</tabTrigger>
<scope>source.php</scope>
</snippet>
<!-- Laravel Model - Custom Primary Key -->
<snippet>
<content><![CDATA[
/**
* Custom primary key for model
* @var string
*/
public \$primaryKey = '${1:custom_key}';
]]></content>
<tabTrigger>laravel:primarykey</tabTrigger>
<tabTrigger>laravel:model:primarykey</tabTrigger>
<scope>source.php</scope>
</snippet>
<!-- Laravel Model - Relation method -->
<snippet>
<content><![CDATA[
/**
* ${2:Relation description}
*
* @return ${7:\Illuminate\Database\Eloquent\Relations\HasMany}
*/
public function ${1:relation}() : ${7:\Illuminate\Database\Eloquent\Relations\HasMany}
{
return \$this->${3:hasMany}('${4:relatedModel}', '${5:relatedModelKey}', '${6:id}');
}
]]></content>
<tabTrigger>laravel:relation</tabTrigger>
<tabTrigger>laravel:model:relation</tabTrigger>
<scope>source.php</scope>
</snippet>
<!-- Laravel Model - Scope -->
<snippet>
<content><![CDATA[
/**
* ${2:Scope description}
*
* @param \Illuminate\Database\Eloquent\Builder \$query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scope${1:NameOfScope}(\$query)
{
return \$query->$3;
}
]]></content>
<tabTrigger>laravel:scope</tabTrigger>
<tabTrigger>laravel:model:scope</tabTrigger>
<scope>source.php</scope>
</snippet>
<!-- Laravel Model - Database table for model -->
<snippet>
<content><![CDATA[
/**
* Database table for model
* @var string
*/
protected \$table = '${1:table}';
]]></content>
<tabTrigger>laravel:table</tabTrigger>
<tabTrigger>laravel:model:table</tabTrigger>
<scope>source.php</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment