Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Eloquent Relationship snippets for Sublime Text
<snippet>
<content><![CDATA[
public function ${1:relationship}()
{
return \$this->belongsToMany(${1/^(.+)$/(?1\u$1:)/g}::class, {$2:table});
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>belt</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
<snippet>
<content><![CDATA[
public function ${1:relationship}()
{
return \$this->belongsTo(${1/^(.+)$/(?1\u$1:)/g}::class);
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>belo</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
<snippet>
<content><![CDATA[
public function ${1:relationship}()
{
return \$this->hasMany(${1/^(.+)$/(?1\u$1:)/g}::class);
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>hasm</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
<snippet>
<content><![CDATA[
public function ${1:relationship}()
{
return \$this->hasOne(${1/^(.+)$/(?1\u$1:)/g}::class);
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>haso</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.php</scope>
</snippet>
@CristianLlanos

This comment has been minimized.

Copy link

CristianLlanos commented Mar 22, 2016

Thanks! That's awesome! 👍 Perhaps belm instead of belt to follow a pattern.

@viralsolani

This comment has been minimized.

Copy link

viralsolani commented Mar 23, 2016

Thanks ! Useful Snippets.

@steveneaston

This comment has been minimized.

Copy link

steveneaston commented Mar 23, 2016

Good snippets, thanks. Just a note, the second tab variable on belongs-to-many should be: ${2:table} (not {$2:table}).

Also worth adding a third tab in so you can quickly delete the table parameter if you don't need it return \$this->belongsToMany(${1/^(.+)$/(?1\u$1:)/g}::class${2:, '${3:table}'});

screen capture on 2016-03-23 at 11-22-05

@mlantz

This comment has been minimized.

Copy link

mlantz commented Mar 23, 2016

Love it!

@AdenFraser

This comment has been minimized.

Copy link

AdenFraser commented Jul 4, 2016

Seems to be a bug with replacing the last 's' in hasMany. Strips the last 's' regardless of whether it is the last character or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.