PHP code example of rtablada / inspector-gadget

1. Go to this page and download the library: Download rtablada/inspector-gadget library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rtablada / inspector-gadget example snippets


class ExampleGadget
{
    public function render()
    {
        return 'this string will be returned';
    }
}

$gadgetFactory->make('ExampleGadget'); // returns 'this string will be returned'

// app/Gadgets/ArgumentGadget.php
class ArgumentGadget
{
    public function render($str)
    {
        return $str . ' from gadget';
    }
}

// view.php
$gadgetFactory->make('ArgumentGadget', 'test'); // returns 'test from gadget'

Gadget::make('ExampleGadget');

@gadget('ExampleGadget')

<div class="sidebar">
    <div class="user-history">
        <h4>History</h4>
         foreach ($userHistory->posts as $historyPost) 

// Controller
public function show($id)
{
    $post = $this->post->find($id);
    $user = $this->auth->user();

    return view('post.show', compact('post', 'user'));
}

// View
<div class="sidebar">
    <div class="user-history">
        <h4>History</h4>
        @gadget('UserPostHistory', $user)
    </div>

    <div class="suggested-articles">
        <h4>Things You Might Like</h4>
        @gadget('RelevantPosts', $post)
    </div>

    <!-- etc. -->
</div>
 php
public function show($id)
{
    $post = $this->post->find($id);
    $relevantPosts = $this->suggestionEngine->relevantPosts($post);
    $comments = $this->comment->allForPost($post);

    $user = $this->auth->user();

    $userHistory = $this->historyCache->historyForUser($user);
    // etc.

    return view('post.show', compact('post', 'relevantPosts', 'comments', 'user', 'userHistory', '...'));
}