new laravel package not recognized - php

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 App\Http\Controllers;
use Illuminate\Http\Request;
use iiiphr\shamsi_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 'iiiphr\shamsi_calendar'.intelephense(1009)
I will appreciate any kind of help :)

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 App\Http\Controllers;
use iiiphr\shamsi_calendar\CalendarController;
class temp extends CalendarController
{
public function index(){
return $this->get_date();
}
}
What do you think about it?

Related

Laravel Lumen in Docker ClassLoader Exception

I installed a fresh Lumen in my docker container. Next I wanted to use eloquent so I activated it and it worked with some tests.
My problem now is if I want to get some Information about the model I've created, most of the times I get an error from the ClassLoader:
"include(/var/www/html/app/Models/Group.php): Failed to open stream: No such file or directory"
The file is obviously there, if I start the request again 1-2 / 10 times it worked. Finds the class and loads all things.
The Model itself has no special stuff in it, just an empty class.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Group extends Model
{
}
In my controller I'm using the model like this:
<?php
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Models\Group;
class TestController extends Controller
{
public function getGroups(Request $request): JsonResponse
{
return response()->json(['groups' => Group::all()]);
}
}
It looks like it has something to do with docker?
Hope someone can help.
Thanks in advance!

Laravel Model not being found

Hi there I am having trouble using a model within a class there error being shown is Error
Class 'App\Models\RegisteredUsers' not found.
I have made sure that the namespaces match what is being used but I repeatedly get the same error.
Model code
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RegisteredUsers extends Model
{
//
}
Controller code
<?php
namespace App\Http\Controllers;
use App\Models\RegisteredUsers;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
class RegisterUser extends Controller
{
$UserObj = new RegisteredUsers();
}
The directory
App/Http/Controllers/RegisterUser - controller
App/Http/Models/RegisteredUser - model
I created the model and the controller using the command line with PHP artisan.
I have tried the solutions from
laravel model class not found
as well as Model not found in Laravel
and a few laracast questions but i still get the error.
May need to rebuild the classmap
composer dump-autoload
With App\Models namespace in your RegsiteredUser model, the RegisteredUser.php model file must be in the app/Models/RegisteredUser.php directory. Try to move the Models folder outside the Http folder. And from now, you should never put the Models folder in the Http folder again.
Your error is App/Http/Models/RegisteredUser and use App\Models\RegisteredUsers;, did you place your Models in Http?. that is not correct, the Models should be in App root directory, so you are calling the RegisteredUser in the wrong place

Class 'App\Http\Controllers\Saml2' not found

I'm on Laravel 5, I'm trying to integrate SAML 2.0 with it. I've found this package = https://github.com/aacotroneo/laravel-saml2
I tried follow their steps, but at the end when I use
<?php
namespace App\Http\Controllers;
class SAMLController extends Controller {
public function adminSignIn(){
return Saml2::login(URL::full());
}
}
I've already added
provider
'Aacotroneo\Saml2\Saml2ServiceProvider',
aliases
'Saml2' => 'Aacotroneo\Saml2\Facades\Saml2Auth',
Why do I still get this error?
Class 'App\Http\Controllers\Saml2' not found
Note : I've even retry after sudo composer dumpauto, same result.
You need to use full namespace for the facade:
\Saml2::login(URL::full());
Or add this to the top of the class:
use Saml2;
you need to explicitly write "use" on top
use Saml2;
This might work.

How to effectively create controller or model without using php artisan?

Why must i use php artisan to create controller or model in laravel. Can i not just use the IDE to create a blank controller or model class?
Sure you could just make your Controllers and Models by hand, but its pretty convenient to use php artisan.
Pretty much all IDE's have support for snippets. You could make snippets for controllers and models.
Controller example snippet
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class YourController extends Controller
{
public function index(Request $request)
{
}
}
Model example snippet
<?php
class ModelExample extends Model
{
protected $table = 'model_table';
}
I prefer and highly recommend using php artisan instead of using your IDE's snippets-feature.
Of course you may use the IDE and create everything from scratch. It's just to help and speed things up.

Laravel 5.1 nested controller class not found

The Laravel documentation clearly describes how to change your routes if you nest your controllers in folders. It seems REALLY simple, and yet I'm still getting an error. Here's the error:
"Class App\Http\Controllers\Input\InputController does not exist"
^That path looks 100% correct to me. What gives?
File Structure:
-Controllers
--Auth
--Input
---InputController.php
Routes:
Route::get('input', 'Input\InputController#getInput');
InputController:
<?php namespace App\Http\Controllers;
use Illuminate\Http\Response;
class InputController extends Controller
{
public function getInput()
{
return response()->view('1_input.input_form');
}
}
Thanks for any help!
Change Controller namespace from
namespace App\Http\Controllers
to
namespace App\Http\Controllers\Input
namespace needs to be changed to the directory your controller is in 'App\Http\Input'
You need to pull in Controller with use App\Http\Controllers\Contoller so that you can extend it.
<?php
namespace App\Http\Controllers\Input;
use App\Http\Controllers\Controller; // need Controller to extend
use Illuminate\Http\Response;
class InputController extends Controller
{
public function getInput()
{
return response()->view('1_input.input_form');
}
}
you should try running a couple commands in your base dir from your terminal (shell/prompt):
composer dump-autoload
or if you don't have composer set as executable:
php composer dump-autoload
and then:
php artisan clear-compiled
This way your laravel would prepare everything again "from scratch" and should be able to find the missing controller class.
Basically laravel generates some additional files to boot up faster. If you define a new class it doesn't get included into that "compiled" file. This way your class should be "introduced" to the framework.

Categories