I am very new in Voyager.
I have got all the controllers inside TCG\\Voyager\\Http\\Controllers while installing Voyager but didn't find other controllers those I have created using BREAD.
Besides that I want to create custom controller in my Voyager admin panel inside App\\Http\\Controllers\\Voyager . I also followed the steps of Voyager tutorial in Youtube for making custom controller, but couldn't create.
Anybody help please ?
In your config\voyager.php file add your namespace:
'controllers' => [
'namespace' => 'App\Http\Controllers\Back',
],
Then publish voyageres controllers to your namespace
php artisan voyager:controllers
Within that namespace create a new controller derived from VoyagerBreadController
namespace App\Http\Controllers\Back;
use Illuminate\Http\Request;
class SchoolController extends VoyagerBreadController
{
Then you can specify the controller in the bread editor.
NOTE: I did have to refer to mine as Back\SchoolController instead of just SchoolController as I would have expected.
Update:
From version 1.1 now you need to extend VoyagerBaseController instead of VoyagerBreadController.
Add this to your model.
use Illuminate\Database\Eloquent\Builder;
protected static function boot()
{
parent::boot();
static::addGlobalScope('order', function (Builder $builder) {
$builder->orderBy('name', 'asc');
});
}
Try this :
composer dump-autoload
php artisan cache:clear
php artisan config:clear
php artisan view:clear
php artisan route:cache
Related
I am developing a custom package where I need an access to the config data. I was able to pull data from config through my blade files, however, when I tried to call it from any custom classes I made, it's throwing an error:
Error: Call to undefined function Acme\Package\config()
What's interesting though, is that, when I tried using the facade Illuminate\Support\Facades\Config, it cannot find the class.
Is there any way I could retrieve data from the config (from the package and/or the app)?
<?php
namespace Acme\Package;
class MyClass {
public function test() {
config('app.name');
}
}
UPDATE: It works when running in the browser (package installed in a Laravel project) but fails when running package's test
UPDATE: If this helps, my package can be found here
Call to the config() is from here
And the test case that fails can be found here
<?php
namespace Acme\Package;
class MyClass {
public function test() {
\Illuminate\Support\Facades\Config::get('app.name');
}
}
Try like this, to use the full namespace to the Config Facade. You could also make a use statement under your namespace to inject the facade and then use Config::get('app.name). The reason it is not working is that your package cannot resolve the namespace of that facade as it is outside of the IoC container
You should try this:
<?php
namespace Acme\Package;
use Config;
class MyClass {
public function test() {
Config::get('app.name');
}
}
Updated answer
Please add below line in config/app.php in aliases section
'Config' => Illuminate\Support\Facades\Config::class,
then run below command
php artisan config:cache
php artisan cache:clear
So, I have a Laravel app with a custom helpers. Everything works fine until I run
php artisan route:cache
I got an error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Cannot redeclare getProperty() (previously declared in /Users/xxxx/xxx/xxx/xxx/xxx/a
pp/Helpers/getProperty.php:4)
The helpers are loaded with HelperServiceProvider:
class HelperServiceProvider extends ServiceProvider
{
public function register()
{
require base_path().'/app/Helpers/getProperty.php';
}
}
The HelperServiceProvider is registered in config/app.php providers list:
'providers'=>[
// ...
App\Providers\HelperServiceProvider::class
];
I patched the issue by wrapping my helper with function_exists('getProperty') condition. However it does not seems the right way to do
Any ideas why Laravel is trying to load my helper twice?
For implement of a Nested Set for my news category I want to use Baum package.
After installing this Package via Composer and add BaumServiceProvider to config/app.php providers, I try to install a new Model named Category via Below command:
php artisan baum:install MODEL
But I faced to the following error :
[InvalidArgumentException]
There are no commands defined in the "baum" namespace.
Of course I ran php artisan command and But there were no command named Baum on generated commands list.
What should I do?
First you have to add the code below in config/app.php:
Baum\Providers\BaumServiceProvider::class
If the problem still persists configuration files may be cached. Just call:
php artisan config:clear
Make sure that you added
Baum\Providers\BaumServiceProvider::class
To the providers array in the app.php file located in config/app.php
Whenever I know that I have added something into Laravel's core files, and it's not working from the command line, I typically just run
php artisan optimize
to regenerate all of the classes, and it will typically work. Running this command is something that I find myself doing fairly often.
In AppServiceProvider.php (app\Providers) you can modify register function: public function register()
{
$this->app->register(\Baum\Providers\BaumServiceProvider::class);
}
Not sure why 5.2 have error, just tweak a bit myself.
Try add this on APP/Console/kernel.php
protected $commands = [
//Commands\Inspire::class,
// Register Baum nestedset command
Commands\BaumCommand::class,
Commands\InstallCommand::class
];
and create two files and copy BaumCommand.php and InstallCommand in /vendor/baum/baum/src/Baum/console.
then change a namespace at the top.
namespace Baum\Commands;
to
namespace App\Console\Commands;
I ran composer update and now I'm running into an issue. I'm getting this error when I'm trying to load my home view:
InvalidArgumentException in FileViewFinder.php line 140:
View [home] not found.
Yes, files exists in my directory (resources/views, etc.). Name is home.blade.php.
My controller:
<?php namespace Hulahoop\Http\Controllers;
use Hulahoop\Http\Requests;
use Hulahoop\Http\Controllers\Controller;
use Illuminate\Http\Request;
class HomeController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
return view('home');
}
}
Route:
Route::get('/', 'HomeController#index');
This was working fine and it's very basic function. What happened? Running on local homestead FYI.
UPDATE: When I run php artisan serve, I can view the home page view fine (i.e. on http://localhost:8000). But on homestead, no dice. What gives?
There seem to be a problem with vagrant and php artisan config:cache.
If you run php artisan config:clear and then try to open the page - you should see it working fine - just make sure you don't cache it via artisan.
Check out [ vendor/config.php ] it's hard-coded for local development.
You need to give executable permission for the view folder 755
What I did:
Added "laravel/socialite": "~2.0" to composer.json
Run composer update
Added provider 'Laravel\Socialite\SocialiteServiceProvider' to app.php
Added alias 'Socialite' => 'Laravel\Socialite\Facades\Socialite' to app.php
After all this steps I created a new Controller Class which looks like that:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AuthController extends Controller {
public function login()
{
return \Socialite::with('facebook')->redirect();
}
}
But i still got this error: PHP Fatal error: Class '\Socialite'
Edit
composer dump-autoload fixed probably the error, but it's still not working correctly.
In your Controllers file add
use Laravel\Socialite\Facades\Socialite;
Just below use Illuminate\Http\Request; in your controller add use Socialize;
Check if you have set your alias as "Socialize" as in the Socialite docs says to do this way:
'Socialize' => 'Laravel\Socialite\Facades\Socialite',
It as very confusing to me as well
I had the same issue. Clearing the config cache helped me in this situation:
php artisan config:clear
First of all use ::class, on your config/app.php
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
Second, call the class in your controller
use Socialite;
Third, try clear the config
php artisan config:clear
And lastly check the redirect URL if its working
http://yoursite.com/your_redirect
If anyone still encounters this problem even after trying above solutions, please clear the cache. Most of the time classes and all are cached because of which this error occurs.
php artisan config:clear
'Socialite' => 'Laravel\Socialite\Facades\Socialite' is a mistake that I did too.
It must be declared as 'Socialite' => Laravel\Socialite\Facades\Socialite::class
I had the exact same problem and after the usual half hour of raging I realised that there was a trailing space at the end of my registration line i.e.
'Laravel\Socialite\SocialiteServiceProvider ',
Once I'd removed the space funnily enough it worked!
'Laravel\Socialite\SocialiteServiceProvider',
Once again the woes of copy and paste raise their ugly heads!
in laravel 6 or above, try running this command
composer require laravel/socialite