php - Laravel 5 custom package class not found -


i creating laravel 5.2 package, following files

packages/
-shreeji/
--ring/
---composer.json
---src/
----ring.php
----ringmodel.php
----ringserviceprovider

composer.json

{  "name": "shreeji/ring",  "description": "simple",  "license": "mit",  "authors": [      {          "name": "author",          "email": "email@gmail.com"      }  ],  "autoload": {         "psr-4": {              "shreeji\\ring\\": "src/"          }      },  "minimum-stability": "dev",  "require": {      "illuminate/support": "~5"  } } 

ring.php

namespace shreeji\ring;  use illuminate\http\response;  class ring {  private $ringmodel; protected $table_name = null;   function __construct() {  }  function set_table($table_name) {     $this->table_name = $table_name;     $this->ringmodel = new ringmodel($this->table_name);     return $this; }  } 

ringmodel.php

use \illuminate\database\eloquent\model eloquent;  class ringmodel extends eloquent {  // set table name; protected $table; protected $primary_key;  public function __construct($table) {     $this->table = $table; } } 

ringserviceprovider.php

namespace shreeji\ring;  use illuminate\support\serviceprovider;  class ringserviceprovider extends serviceprovider { public function register() {     $this->app->bind('ring', function($app){         return new ring;     }); }  public function boot() {  } } 

and in app/http/controllers have created test file this

ringcontroller.php

namespace app\http\controllers;  use app\http\controllers\controller; use shreeji\ring;  class ringcontroller extends controller {   public function index()  {      $ring = new ring();      $ring->set_table('ring');  } } 

in routes.php

route::get('ringtest', [ 'as' => 'ringtest', 'uses' => 'ringcontroller@index' ]); 

i have added service provider in config/app.php as

shreeji\ring\ringserviceprovider::class, 

in composer.json have added as

..... "psr-4": {         "app\\": "app/",         "shreeji\\ring\\": "packages/shreeji/ring/src"     } ..... 

when call ringtest browser following error.

fatalerrorexception in ringcontroller.php line 19: class 'shreeji\ring' not found

what wrong code why class not found have run composer dumpautoload.

in controller have:

use shreeji\ring; 

but, must be:

use shreeji\ring\ring; 

the first 'ring' directory (namespace). second 'ring' class.

your model not in namespace. first line of model must be:

namespace shreeji\ring; 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -