Usage
Usage
To start using Trickster, you will be needed to set it up first. Follow the below steps to setup Trickster:
1. Service Provider
You will be needing to add the Trickster Service Provider in your app.php which is inside the config directory.
- Open
config\app.php - Find
'providers' - At the last of this array in
Application Service ProvidersaddSecrethash\Trickster\TricksterServiceProvider::class,
2. Facade
To use Trickster flexibly, you need to add the Facade also. Facade will let you use Trickster directly. All you will need to do is add use Trickster; at the head of the controller below namespace and use it by Trickster::trickName();
Lets Add the Trickster Facade:
- Open
config\app.php - Find
'aliases'array. - At the end of this array, add
'Trickster' => Secrethash\Trickster\Facade\Trickster::class,
Note
This command will publish the trickster.php configuration file for Trickster to your application default config directory.
From config\trickster.php you can edit the default configurations.
4. Ready, Steady, GO!
You are almost done. Now what to do when you want to use a Trickster's Trick?
Here is a sample Controller to show you how to add Trickster and Use it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests; use Auth; use Trickster; // Simply add the Facade class TricksterDemoController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //checking if the user is Authenticated if (Auth::check()) { $user = Auth::user(); // Grabbing Gravatar $gravatar = Trickster::gravatar($user->email, '200'); } } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } } |
If you want to use Trickster inside a view file, call the Trickster method directly. That is the advantage of Facade.
Example:
Ex1: {!! Trickster::bbcode($user->bio) !!}
Ex:2 {{ Trickster::truncator($blog->desc, '150', '(...summary)') }}