title: How to use a package in laravel
body: <p>I want to use this package <a href="https://github.com/AbdullahGhanem/rating" rel="nofollow noreferrer">https://github.com/AbdullahGhanem/rating</a>. I am having trouble while using it. I have installed the package.I want to know where should I place this code <code>$post-&gt;averageRating()</code> and I have created rating in Controller. Is that the right way to do?</p>
  
  <p>Here is my layout code:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/style&gt;
  &lt;!-- Latest compiled and minified CSS --&gt;
  &lt;link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"&gt;
  
  &lt;!-- Optional theme --&gt;
  &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"&gt;
  
  &lt;!-- Latest compiled and minified JavaScript --&gt;
  &lt;script  src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"&gt;&lt;/script&gt;
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="row new-post"&gt;
      &lt;div class="col-md-6 col-md-offset-3"&gt;
  
          &lt;header&gt;&lt;h3&gt;Comments&lt;/h3&gt;&lt;/header&gt;
          &lt;form action="/comments" method="post"&gt;
          {{csrf_field()}}
              &lt;div class="form-group"&gt;
                  &lt;textarea class="form-control" name="body" id="new-post" rows="5" placeholder="Your review on above game"&gt;&lt;/textarea&gt;
              &lt;/div&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;Post  Comment&lt;/button&gt;
  
          &lt;/form&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  
  
      @foreach($comments as $comment) 
  &lt;h1&gt;{{$comment-&gt;body }}&lt;/h1&gt;
  @endforeach
  
  {{$post-&gt;averageRating();}}
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>Here is my Controllers code:-
      
  
  <pre><code>namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Comment;
  use Auth;
  
  use Illuminate\Support\Facades\DB;
  
  
  
  
  class CommentsController extends Controller
  {
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function index()
  {
      //
  }
  
  /**
   * Show the form for creating a new resource.
   *
   * @return \Illuminate\Http\Response
   */
  public function create()
  {
      //
      $comments = comment::all();
      $post=Post::all();
  return view('comments.create', ['comments' =&gt; $comments]);
  
  
  }
  
  /**
   * Store a newly created resource in storage.
   *
   * @param  \Illuminate\Http\Request  $request
   * @return \Illuminate\Http\Response
   */
  public function store(Request $request)
  {
  
  
      $comment= new Comment();
      $comment-&gt;user_id=Auth::user()-&gt;id;
      $comment-&gt;body=$request-&gt;body;
      $comment-&gt;save();
      return back();
  
    $user = User::first();
    $post = Post::first();
  
    $rating = $post-&gt;rating([
    'rating' =&gt; 5
     ], $user);
  
   dd($rating);
  
   }
  
  /**
   * Display the specified resource.
   *
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
  public function show()
  {
      //
  
  }
  
  /**
   * Show the form for editing the specified resource.
   *
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
  public function edit($id)
  {
      //
  }
  
  /**
   * Update the specified resource in storage.
   *
   * @param  \Illuminate\Http\Request  $request
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
  public function update(Request $request, $id)
  {
      //
  }
  
  /**
   * Remove the specified resource from storage.
   *
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
  public function destroy($id)
  {
      //
  }
  
  
  }
  </code></pre>
  
  <p>here is my model code :-</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Ghanem\Rating\Contracts\Rating;
  use Ghanem\Rating\Traits\Ratingable as RatingTrait;
  use Illuminate\Database\Eloquent\Model;
  
  class Post extends Model implements Rating
  {
  //
  
  
  use RatingTrait;
  }
  </code></pre>
  
  <p>here is the code in web.php:-
      
  
  <pre><code>Route::get('/', function () {
  return view('welcome');
  });
  
  Auth::routes();
  
  Route::get('/home', 'HomeController@index');
  //comments
  Route::resource('comments','CommentsController');
  //like
  Route::post('/like', [
  'uses' =&gt; 'LikeController@postLikePost',
  'as' =&gt; 'like'
  ]);
  </code></pre>
  
  <p>code in my app.php</p>
  
  <pre><code>&lt;?php
  
  return [
  
  /*
  |--------------------------------------------------------------------------
  | Application Name
  |--------------------------------------------------------------------------
  |
  | This value is the name of your application. This value is used when the
  | framework needs to place the application's name in a notification or
  | any other location as required by the application or its packages.
  */
  
  'name' =&gt; 'Laravel',
  
  /*
  |--------------------------------------------------------------------------
  | Application Environment
  |--------------------------------------------------------------------------
  |
  | This value determines the "environment" your application is currently
  | running in. This may determine how you prefer to configure various
  | services your application utilizes. Set this in your ".env" file.
  |
  */
  
  'env' =&gt; env('APP_ENV', 'production'),
  
  /*
  |--------------------------------------------------------------------------
  | Application Debug Mode
  |--------------------------------------------------------------------------
  |
  | When your application is in debug mode, detailed error messages with
  | stack traces will be shown on every error that occurs within your
  | application. If disabled, a simple generic error page is shown.
  |
  */
  
  'debug' =&gt; env('APP_DEBUG', false),
  
  /*
  |--------------------------------------------------------------------------
  | Application URL
  |--------------------------------------------------------------------------
  |
  | This URL is used by the console to properly generate URLs when using
  | the Artisan command line tool. You should set this to the root of
  | your application so that it is used when running Artisan tasks.
  |
  */
  
  'url' =&gt; env('APP_URL', 'http://localhost'),
  
  /*
  |--------------------------------------------------------------------------
  | Application Timezone
  |--------------------------------------------------------------------------
  |
  | Here you may specify the default timezone for your application, which
  | will be used by the PHP date and date-time functions. We have gone
  | ahead and set this to a sensible default for you out of the box.
  |
  */
  
  'timezone' =&gt; 'UTC',
  
  /*
  |--------------------------------------------------------------------------
  | Application Locale Configuration
  |--------------------------------------------------------------------------
  |
  | The application locale determines the default locale that will be used
  | by the translation service provider. You are free to set this value
  | to any of the locales which will be supported by the application.
  |
  */
  
  'locale' =&gt; 'en',
  
  /*
  |--------------------------------------------------------------------------
  | Application Fallback Locale
  |--------------------------------------------------------------------------
  |
  | The fallback locale determines the locale to use when the current one
  | is not available. You may change the value to correspond to any of
  | the language folders that are provided through your application.
  |
  */
  
  'fallback_locale' =&gt; 'en',
  
  /*
  |--------------------------------------------------------------------------
  | Encryption Key
  |--------------------------------------------------------------------------
  |
  | This key is used by the Illuminate encrypter service and should be set
  | to a random, 32 character string, otherwise these encrypted strings
  | will not be safe. Please do this before deploying an application!
  |
  */
  
  'key' =&gt; env('APP_KEY'),
  
  'cipher' =&gt; 'AES-256-CBC',
  
  /*
  |--------------------------------------------------------------------------
  | Logging Configuration
  |--------------------------------------------------------------------------
  |
  | Here you may configure the log settings for your application. Out of
  | the box, Laravel uses the Monolog PHP logging library. This gives
  | you a variety of powerful log handlers / formatters to utilize.
  |
  | Available Settings: "single", "daily", "syslog", "errorlog"
  |
  */
  
  'log' =&gt; env('APP_LOG', 'single'),
  
  'log_level' =&gt; env('APP_LOG_LEVEL', 'debug'),
  
  /*
  |--------------------------------------------------------------------------
  | Autoloaded Service Providers
  |--------------------------------------------------------------------------
  |
  | The service providers listed here will be automatically loaded on the
  | request to your application. Feel free to add your own services to
  | this array to grant expanded functionality to your applications.
  |
  */
  
  'providers' =&gt; [
  
      /*
       * Laravel Framework Service Providers...
       */
      Illuminate\Auth\AuthServiceProvider::class,
      Illuminate\Broadcasting\BroadcastServiceProvider::class,
      Illuminate\Bus\BusServiceProvider::class,
      Illuminate\Cache\CacheServiceProvider::class,
      Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
      Illuminate\Cookie\CookieServiceProvider::class,
      Illuminate\Database\DatabaseServiceProvider::class,
      Illuminate\Encryption\EncryptionServiceProvider::class,
      Illuminate\Filesystem\FilesystemServiceProvider::class,
      Illuminate\Foundation\Providers\FoundationServiceProvider::class,
      Illuminate\Hashing\HashServiceProvider::class,
      Illuminate\Mail\MailServiceProvider::class,
      Illuminate\Notifications\NotificationServiceProvider::class,
      Illuminate\Pagination\PaginationServiceProvider::class,
      Illuminate\Pipeline\PipelineServiceProvider::class,
      Illuminate\Queue\QueueServiceProvider::class,
      Illuminate\Redis\RedisServiceProvider::class,
      Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
      Illuminate\Session\SessionServiceProvider::class,
      Illuminate\Translation\TranslationServiceProvider::class,
      Illuminate\Validation\ValidationServiceProvider::class,
      Illuminate\View\ViewServiceProvider::class,
  
      /*
       * Package Service Providers...
       */
  
      //
  
      /*
       * Application Service Providers...
       */
      App\Providers\AppServiceProvider::class,
      App\Providers\AuthServiceProvider::class,
      // App\Providers\BroadcastServiceProvider::class,
      App\Providers\EventServiceProvider::class,
      App\Providers\RouteServiceProvider::class,
      Ghanem\Rating\RatingServiceProvider::class,
  
  ],
  
  /*
  |--------------------------------------------------------------------------
  | Class Aliases
  |--------------------------------------------------------------------------
  |
  | This array of class aliases will be registered when this application
  | is started. However, feel free to register as many as you wish as
  | the aliases are "lazy" loaded so they don't hinder performance.
  |
  */
  
  'aliases' =&gt; [
  
      'App' =&gt; Illuminate\Support\Facades\App::class,
      'Artisan' =&gt; Illuminate\Support\Facades\Artisan::class,
      'Auth' =&gt; Illuminate\Support\Facades\Auth::class,
      'Blade' =&gt; Illuminate\Support\Facades\Blade::class,
      'Bus' =&gt; Illuminate\Support\Facades\Bus::class,
      'Cache' =&gt; Illuminate\Support\Facades\Cache::class,
      'Config' =&gt; Illuminate\Support\Facades\Config::class,
      'Cookie' =&gt; Illuminate\Support\Facades\Cookie::class,
      'Crypt' =&gt; Illuminate\Support\Facades\Crypt::class,
      'DB' =&gt; Illuminate\Support\Facades\DB::class,
      'Eloquent' =&gt; Illuminate\Database\Eloquent\Model::class,
      'Event' =&gt; Illuminate\Support\Facades\Event::class,
      'File' =&gt; Illuminate\Support\Facades\File::class,
      'Gate' =&gt; Illuminate\Support\Facades\Gate::class,
      'Hash' =&gt; Illuminate\Support\Facades\Hash::class,
      'Lang' =&gt; Illuminate\Support\Facades\Lang::class,
      'Log' =&gt; Illuminate\Support\Facades\Log::class,
      'Mail' =&gt; Illuminate\Support\Facades\Mail::class,
      'Notification' =&gt; Illuminate\Support\Facades\Notification::class,
      'Password' =&gt; Illuminate\Support\Facades\Password::class,
      'Queue' =&gt; Illuminate\Support\Facades\Queue::class,
      'Redirect' =&gt; Illuminate\Support\Facades\Redirect::class,
      'Redis' =&gt; Illuminate\Support\Facades\Redis::class,
      'Request' =&gt; Illuminate\Support\Facades\Request::class,
      'Response' =&gt; Illuminate\Support\Facades\Response::class,
      'Route' =&gt; Illuminate\Support\Facades\Route::class,
      'Schema' =&gt; Illuminate\Support\Facades\Schema::class,
      'Session' =&gt; Illuminate\Support\Facades\Session::class,
      'Storage' =&gt; Illuminate\Support\Facades\Storage::class,
      'URL' =&gt; Illuminate\Support\Facades\URL::class,
      'Validator' =&gt; Illuminate\Support\Facades\Validator::class,
      'View' =&gt; Illuminate\Support\Facades\View::class,
  
  ],
  
  ];
  </code></pre>
  
  <p>thanks in advance :-)</p>