I am quite new to Livewire and I feel a little bit confused about its folder structure.
I use the classic Laravel folder structure for my views and I put the components under the /resources/views folder; now with Livewire it seems that I am forced to put my components under /resources/views/livewire folder otherwise the component throws an error.
I also tried to change the view_path in my config/livewire.php file to resource_path('views'), instead of resource_path('views/livewire'), but it doesn't work.
The result is a messy structure like the following, where the users' components are in a different folder and I have to go back and forth to find what I want.
Wouldn't it be possibile to remove the /resources/views/livewire folder and put the components under the relative folder they belong to?
resources
views
users
index.blade.php
livewire
users
table.blade.php
the answer is the config file /config/livewire.php
'view_path' => resource_path('views/livewire'),
Just make sure you update all the Livewire class files views in their render function and that you clear any stale config information
php artisan cache:clear
edit: I have tested this and have regular Laravel blades along side livewire ones.
Related
I wanted to add a controller to an already existing project of mine. Wrote a controller file, added the link in the admin_api route file and adjusted the view I needed.
On my local machine everything works fine.
On production it failed (it's supposed to retrieve a collection, which is then handled and displayed by a vue js component) and the network monitor showed an error 500.
I ssh into the website and ran php artisan route:list which gave me the error
In Container.php line 779:
Class App\Http\Controllers\Admin\Api\StatsController does not exist
Although the file StatsController is in App\Http\Controllers\Admin\API\
After playing around I realized that the problem was with the folder name "API", as laravel was looking for "Api". So apparently it's case sensitive.
Placing the controller in a new folder "Api" solved the issue.
Moving all the other "API" controllers to "Api" broke their routes.
when running php artisan route:list and in RouteServiceProvider all routes appear as under Admin/Api.
What I don't get is where is this being registered? Is there a way to change this?
I find it quite annoying that the controllers sit now in separate folders and it seems quite absurd to me. I don't quite get how the original controllers worked if they seem to contradict the other configurations.
Working with Laravel 5.7
I would appreciate any insights!
Thanks
Just put all the relevant api controllers in a folder named Api or API (just pick a convention and stick with it), then make sure that each file's namespace (declared at the top) is correct and reflects the folder structure you have chosen.
For example, if your controllers are in app/Http/Controllers/Admin/Api, check that each controller file begins with:
<?php
namespace App\Http\Controllers\Admin\Api;
// Rest of code...
StatsController.php must have the namespace as App\Http\Controllers\Admin\API. In Controller.php you have to import as App\Http\Controllers\Admin\API\StatsController. After that, run composer dump-autoload
in laravel (localhost and online hosting )how to display image in home.blade.php or any page, from out side of laravel project (out side of root folder)
i tried this two code but not work.
<div><img src="file:///C:/USER/User_Profile_Image/{{ Auth::user()->image }}" alt="profile"/></div>
<div><img src="file:///C:/USER/User_Profile_Image/default.jpeg" alt="profile"/></div>
Before I give you an answer I just wanted to mention, I wouldnt suggest accessing anything outside of your project directory, this can cause many problems when it comes to relocation of the project or if a file structure changes.
Possible Solution (Not Recommended)
If you had reasoning to have to access something outside of the laravel directory you can just use the '..' which means going into the parent folder.
Example
<img src="../../../User_Profile_Image/default.jpeg" alt="profile"/>
Other than that you could look into some straight PHP things around the documentation.
Alternatives ()
If you are trying to store and access images in a public place you can use the public folder in laravel. Everything in this folder can be accessed by the public and is made to store publicly accessible things in such as profile pictures.
Public Example
use Illuminate\Support\Facades\Storage;
Storage::put('file.jpg', $contents);
<img src="/file.jpg" alt="profile"/>
Hope this answered your question, good luck!
I've SSH into the server and into the Laravel folder. I updated one of the html footer files but the changes aren't reflected on the website. I feel like I probably need to recompile something.
I tried deleting and re-creating the .env file (I backed it up first).
I've tried running the following commands:
php artisan clear-compiled
php artisan optimize
php artisan cache:clear
The only way I can seem to update the site is by updating the main.min.js file, located at /laravel/public/assets/js/main.min.js which is a terrible way to update the site.
How do I force Laravel to recreate this file or recompile the site based on changes I made to html template files within the site?
What am I missing here? I don't have any Laravel experience and am trying to update this site for a client.
edit:
I think I need to clarify a bit more...
The site appears to be rendered from this file: /public/assets/js/main.min.js
Most of the site's homepage, for example, is located in this js file. But the file is minified and therefore unwieldy to edit directly.
I am assuming (and I could be completely wrong here) that the file is generated from the html files located in the Laravel folder. To support this notion, I have found html files in other directories that correspond to the html located in the main.min.js file.
My assumption is that the previous developer would update the html files and then run something to compile the site into javascript files. But maybe this has nothing to do with Laravel, per se, and more to do with some frontend framework?
Try clearing the cached views...
php artisan view:clear
Laravel assets reside in
resources/assets/js
of your root directory you can have look their
if your file main.js is build using laravel mix have a on webpack.mix.js which compiles all your files you can get idea from that. make sure to run
npm run prod
if you change any file
Hope this helps?
I updated my laravel app from 5.2 to 5.3 then 5.4 (To avoid problems with direct update). The update was successful and my app is working fine. But then I can't find changes in the folder structure. A particular change I will like to see is my routes.php file leaving from root/app/Http/ to root/routes/.
I am wondering if this is normal and how I can modify it to take the new structure thanks in advance!
Well, if you update your app, those changes won't be made automatically. In upgrade guide there are only described changes that are necessary to make your application work.
When we are talking about routes, it's not so important, so you can have them as you had before or if you want you can move them and also rename those files (now there is no routes.php file but web.php, api.php and console.php files).
To move routes into new structure you should compare https://github.com/laravel/laravel/blob/5.2/app/Providers/RouteServiceProvider.php with https://github.com/laravel/laravel/blob/master/app/Providers/RouteServiceProvider.php - so you need to update your RouteServiceProvider file and move files into new locations.
I am new to Laravel 4, and I come from a Zend Framework background. I'd like to create a folder app/forms and keep all my forms there. How can I refer to the form in the controller and within the view.blade files?
By default, the root of the view files folder is app/views so if you create a folder in views like app/views/forms then you may refer the form by it's name from a controller like:
$form = View::make('forms.formfile');
Here, formfile is the name of the file that contains the form and it could be formfile.blade.php and to refer/include the form file from a view you may use #include:
// In a blade view file
#include('forms.form1')
Assume that, form1 is a blade view inside the forms folder and saved as form1.blade.php, you may also use sub-folders inside the forms folder, for example in views/forms/user folder you may keep a view named index.blade.php and use it like:
// From a controller
$userForm = View::make('forms/user/index');
From a view file: (folders are separated by .)
#include('forms.user.index') // file: app/views/forms/user/index.blade.php
You can also nest views in the controller, check the manual for more.
From the standpoint of Laravel, HTML forms (and all presentation related things ) belongs to app/views/ folder. Exceptions are package specific views. For example some commands has their own stubs and views and they are usually stored inside package.
Laravel is very flexibile, and you can move things around and create new folders and namespaces. You just have to tell composer that you are changing Laravel default structure, and dumpautoload. That is if you only want to create new folder with internal reference. If you want something with more scope and visibility you'll have to bind that to container, so that will be visible inside whole application.
You are coming from the Zend world, so I can understand that you want to move some of Zend "flavour" to Laravel. Although is it possible, I would really recommend you to take some time and learn how Laravel works. There are some great ideas and design inside. Of course, Zend has its own quality, but hey - this is Laravel :)