So, I'm exploring the world of Jetstream and Fortify. Problem is that I want to change the default app.blade.php to my folder admin/app.blade.php.
Where is this defines so I can change it? Can't find it anywhere.
Many thanks!
(Ps: Don't know if this is categorised under Laravel of Vue.)
Update: To avoid confusion. I installed a fresh installation of Laravel with Jetstream. I'm using Inertia for developing my CMS. Inertia has a default file in /views. This is called app.blade.php, which calls #inertia. I want to move this file to /views/admin. If I do that, I get this error:
View [app] not found.
Which makes sense, because I moved it. Where do I change the render of app.blade.php to change it to admin/app.blade.php?
UPDATE:
You can register this in your AppServiceProvider.
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Inertia\Inertia;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* #return void
*/
public function register()
{
if (request()->is(['admin', 'admin/*'])) {
Inertia::setRootView('admin.app');
}
Inertia::setRootView('app');
}
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
//
}
}```
do like this
YourProjectPath/config/view.php
'paths' => [
resource_path('views/admin'),
],
if in Controller you can do like this
return view('admin.app');
Related
I just created a simple Laravel CLI package in Laravel 8. My custom command doesn't appear in php artisan list and the provider needs to register manually into config/app.php to make it work. As far as I know, we don't need to register the provider manually in Laravel 5.5+.
Here is my provider source code:
<?php
namespace Robyfirnandoyusuf\BadOmen;
use Illuminate\Events\Dispatcher;
use Illuminate\Support\ServiceProvider;
use Robyfirnandoyusuf\BadOmen\Commands\Migrate;
class BadOmenServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([
Migrate::class
]);
}
}
public function register()
{
}
}
and this is the structure of the directories:
Anyone have solution for this problem?
Solved, by adding providers property in the package's composer.json file, with a value of [Robyfirnandoyusuf\BadOmen\BadOmenServiceProvider::class]
. I want to implement this package in my laravel. Package link is below:-
https://github.com/joshdick/miniProxy/blob/master/miniProxy.php
Its working fine when i run using php file. But i don't knw how to implement this package file in laravel. This package contains only one file. Can anyone guide me or help me how to do this package functioning in laravel.
You can simply include this file in your class. Put it somewhere meaningful, like /vendor or /lib and include it in the class where you want to use it.
Some information on including external PHP files: https://laraveldaily.com/how-to-use-external-classes-and-php-files-in-laravel-controller/
simply add it in your composer.json
You can create a ServiceProvider like this in app/Providers :
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class HelperServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot()
{
//
}
/**
* Register the application services.
*
* #return void
*/
public function register()
{
foreach (glob(app_path().'/Helpers/*.php') as $filename) {
require_once($filename);
}
}
}
In you config/app file, add this new serviceProvier
App\Providers\HelperServiceProvider::class,
Then create a folder /Helpers in /app folder (./app/Helpers) and put your file in this folder.
Now you can access all this folder functions from everywhere.
I recently started using laravel so i'm a beginner, and right now i'm working on a small project which requires me use shortcodes(like the ones in wordpress).
So i searched for a little bit and found this package:
https://packagist.org/packages/webwizo/laravel-shortcodes
I ran the installation and usage the way it's written but i get the error : Class 'App\Providers\Shortcode' not found in the provider I have to make using the laravel make:provider command as specified in the package instructions, below is my exact usage and install code.
added this to the providers array :
/*
* shortcodes providers
*/
Webwizo\Shortcodes\ShortcodesServiceProvider::class,
App\Providers\ShortcodesServiceProvider::class,
Added this to aliases:
'Shortcode' => Webwizo\Shortcodes\Facades\Shortcode::class,
this is the content of my ShortcodesServiceProvider in app/providers:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Shortcodes\JobsForm;
class ShortcodesServiceProvider extends ServiceProvider
{
/**
Bootstrap the application services.
*
#return void
*/
public function boot()
{
//
}
/**
Register the application services.
*
#return void
*/
public function register()
{
Shortcode::register('jobs', JobsForm::class);
}
}
I use laravel 5.4 so that might be an issue.
The thing is the class obviously exists, it gives the Shortcodes class not found error because I think it searches for it in the app/providers/ShortcodesServiceProvider file, and obviously it's not there it's in the vendor file.
Is there something I'm missing i've checked and double checked, I can't seem to get this thing to work.
It shoould work considering it has an alias defined right ?
I used it in the view like this:
return view('quarx-frontend::pages.' . $page->template)->with('page', $page)->withShortcodes();
Thanks for taking the time to read this any help would be much appreciated.
If you need any more info I'll be glad to supply it.
p.s. sorry for bad english ,not a native speaker :P
It searches for Shortcode in the App\Providers; namespace and not in the root namespace where the Facade is defined.
You can fix this in App\Providers\ShortcodesServiceProvider.php by either doing:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Shortcodes\JobsForm;
use Shortcode;
class ShortcodesServiceProvider extends ServiceProvider
{
Or use \Shortcode
/**
* Register the application services.
*
* #return void
*/
public function register()
{
\Shortcode::register('jobs', JobsForm::class);
}
I would recommend the first option.
I just read the Laravel 5 doc on configuration based on your environment http://laravel.com/docs/5.0/configuration#environment-configuration
I understand how the .env files can be used to configure some variables but how do I configure what service providers get loaded based on the environment?
For example in my ''local'' environment I use this debugbar plugin which needs a service provider but I don't want to define it in config/app.php for production.
In Laravel 4.2 I could just create config/local/app.php but that doesn't seem to work anymore, what is the alternative?
This article was helpful for me:
https://mattstauffer.co/blog/conditionally-loading-service-providers-in-laravel-5
And this is what I've done and it works:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
if ($this->app->environment('local')) {
$this->app->register('Barryvdh\Debugbar\ServiceProvider');
}
}
}
I believe if you set APP_DEBUG to false in your .env file the debugbar will go away automatically.
Also I wrote a middleware class to take care of that.
The handle method could look like this in your case:
public function handle($request, Closure $next)
{
if (app()->environment('production'))
\Debugbar::disable();
else
\Debugbar::enable();
return $next($request);
}
Then you just add it to the list of middleware in app/Http/kernel.php and you're good to go.
I have some additional conditions and more environments so this exact code is not tested but it should work and you should get the idea.
Take care.
Following the view composer documentation I've created a class ComposerServiceProvider and a ViewComposer for my basic views. I want to use another view composer for the administration area of my site called AdminComposer. These are my class headers:
(namespace App\Http\Composers)
class ViewComposer
class AdminComposer extends ViewComposer
This is my Composer Service provider:
<?php namespace App\Providers;
use View;
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider {
/**
* Register bindings in the container.
*
* #return void
*/
public function boot()
{
View::composer('admin/*', 'App\Http\Composers\AdminComposer');
View::composer('*', 'App\Http\Composers\ViewComposer');
}
/**
* Register any application services.
*
* #return void
*/
public function register()
{
//
}
}
In the method boot() of my composer service provider I want to assign the ViewComposer to all my views, except for the ones with the prefix "admin", which should use AdminComposer.
In the current setting however, both view composers are used, as path "admin/*" adheres to path "*/" as well. Is there a way I can exclude the admin prefix from the wildcard path, without having to individually declare all paths that will use ViewComposer instead?
It's probably enough to only attach the view composers to your two layout files. This way you not only resolve the conflict between normal and admin views but also the composer runs just once per request and not twice or more (for the view and the layout view and possibly more views)
View::composer('layouts.admin', 'App\Http\Composers\AdminComposer');
View::composer('layouts.master', 'App\Http\Composers\ViewComposer');