I was writing my first laravel package, so I could use it and understand how packages work and learn how to write packages and etc.
But my project didn’t recognize the package that I wrote.
Here is my package Github link: https://github.com/IIIphr/Shamsi_Calendar
And this is my main project: https://github.com/IIIphr/aimeos_shamsi
I use this command to add my package to the app: composer require iiiphr/shamsi_calendar
And it’ll be added successfully (at least I guess). Then in the temp Controller, I wrote this:
<?php namespace AppHttpControllers; use IlluminateHttpRequest; use iiiphrshamsi_calendar; class temp extends Controller { public function index(){ return shamsi_calendar::get_date(); } }
And a route:
Route::get('/date','temp@index');
But in the http://localhost:8000/date
, I will face this error:
Before, I have tried other ways and the result was anything but success.
Another thing, I have this error in visual studio code in the temp controller:
Undefined type 'iiiphrshamsi_calendar'.intelephense(1009)
I will appreciate any kind of help 🙂
Advertisement
Answer
You import the library perfectly but you don’t use the Calendar Controller that the package gives you. The package haves a controller called CalendarController, you have two ways, extends from this controller or create an instance of this controller, if you extend the controller from this:
<?php namespace AppHttpControllers; use iiiphrshamsi_calendarCalendarController; class temp extends CalendarController { public function index(){ return $this->get_date(); } }
What do you think about it?