Laravel Project is installed in my root directory and I have another project inside root directory with Core PHP ,
COREPHP-PROJECT is the one I want to access , but every time I try to access example.com/COREPHP-PROJECT it's giving me 404 error.
I have tried more than 50 solutions from internet and nothing is working so far.
What I'm doing wrong here?
NOTE: .htaccess file is renamed as I wanted to test without it too.
I think it is actually fine to have a project directory inside the applications root directory. A good application should not be build inside the framework. It should be build with the framework. If in 5 years somehow laravel is not anymore supported you can decouple it more easy and use it in a new framework.
You just need to assign the path to your composer.json under the psr-4 part.
"autoload": {
"psr-4": {
"MainApplication\\": "app/",
"CorePhpProject\\": "CORE-PHP-PROJECT/app/",
But you should only route over the Laravel router.
You can add your routes inside laravels RouteServiceProvider.php
Have a look at the documentation:
https://laravel.com/docs/8.x/routing#the-default-route-files
Should look something like this then:
Route::prefix('coreproject')
->group(base_path('CORE-PHP-PROJECT/routes/web.php'));
Then you can call your laravel routes like this
/home
and the project one are called like /coreproject/home
I got into same task of integrating core php folder inside laravel , therefore solution i found that create a core php file with extension test.php in public folder at laravel root, and try to access in browser after php artisan serve, you will find you can access it.
Related
I’m in the middle of the process of replicating a framework that I developed in node / react to laravel. Right now, I’m adjusting the main architecture and currently working on a blade master page.
My original idea (Laravel 8 – use blade asset to display image, but loading from resources subfolder) didn’t work, so I’m trying a new approach to set up how I want my asset files to be served.
The assets in question is basically images for layout purposes. I organized the directory like so:
public/app_files_layout
Inside it, I have a bunch of image files that I want to access. The thing is that I don’t want to access like http://localhost:8000/app_files_layout/image-name.jpg. My intention is to access like: http://localhost:8000/images/image-name.jpg, but I want to maintain the directory names I created intact, so it can have a high fidelity architectural organization similar to my framework that I built in other languages.
I figured that I would set up a simple routing logic for it in Laravel web.php file. I followed the suggestion from this stackoverflow question:
https://stackoverflow.com/a/38736973/2510785
However, when I try to access via browser through the following address http://localhost:8000/files-layout-test/image-name.jpg, returned me an error like so:
The requested resource /files-layout-test/image-name.jpg was not found on this server.
I stripped the code just to try to find out what could be wrong, and this is what I did to debug it:
Route::get('/files-layout-test/{filename}', function($filename){
echo 'debug';
});
The strange behavior is that, when I try to access without the file extension (ex: http://localhost:8000/files-layout-test/image-name), it goes through, but I need the file extension to be there.
Any ideas on how I could get this done?
Note: I’m new to Laravel, so the answer may be simple.
Basically for simple stuff like creating a symlink for public/images and public/app_files_layout you can use the built-in storage:link command.
In your config/filesystems.php file, you can define the symlinks you want to create
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('images') => public_path('app_files_layout'),
],
Then you can run php artisan storage:link and it will create all the symlinks defined the links array in config/filesystems.php. No need to create any custom Artisan command. You can read more at Laravel Docs
With the above symlink created you can use the asset() helper to generate the urls for assets which are actually in public/app_files_layout using asset('images/filename.ext').
You can also access public/app_files_layout/image-name.ext at http://localhost:8000/images/image-name.ext once the symlink is created.
However if you want to add some other logic or say you want to get user input for creating symlinks then you can define your own custom Artisan command using the storage:link command as starting point
Currently my directory is var/www/
but i have other projects in this directory .for example:
var/www/wordpress/
laravel tell me :
Sorry, the page you are looking for could not be found.
how can change laravel directory to var/www/cms ?
does work another project?
how can do that?
I commented earlier .. But I think to make the comment more clear I am going to go ahead and answer this:
First what you need to do is cd into /var/www/cms
Next you need to create your Laravel application. While in the cms directory, issue your Laravel creation command IE composer create-project laravel/laravel your-project-name. Once it is finished .. You should have a directory in the cms directory named whatever you named your Laravel Project IE var/www/cms/your-project-name.
You then need to point your hosts file (whether Nginx or Apache) to the directory var/www/cms/your-project-name for whatever domain.
I hope this was simplified enough for you, and good luck!
Laravel Valet could be one of the Solution.
You could create seperate Host for your Specific Application at Localhost.
Explained here : https://stackoverflow.com/questions/19425086/alias-hostname-for-localhost
You could Create new Directory and run your Laravel Project there too.
Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.
Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.
Basically, I can't start the Angular application at all with this setup.
How can I overcome this?
In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.
I make API with Laravel and use it with Angular 2.
In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves.
I also use gulp to copy the built files from /dist to /public
I had the same problem and what I found is this related issue in their GitHub issues:
The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.
This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.
So, you can't really achieve what you exactly want, but this is the only workaround I found.
I found only one solution for me.
create build for client side code by ng build --prod
Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
Using gulp-ingect plugin inject copied files into layout gulp inject
-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>
-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).
P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.
Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there…
And add an appropriate route into Laravel routing. Like this one, for instance:
Route::any('{path?}', function () {
return File::get(public_path() . '/index.html');
})->where("path", ".+");
Btw, it’s simply a trap for any unknown routes… But I think you get an idea.
I have just installed a new installation of Laravel using composer as per the laravel docs. The documentation refers to the app/routes.php file which is used to map routes to controllers or closed functions. First, there was no app/routes.php file so I created one. Now the routes I've copied from the laravel documentation aren't being found when accessing via the browser. In fact the app/routes.php file isn't even being found by the application as I have put a die statement in there and nothing. It has nothing to do with .htaccess. I am using the default .htaccess and redirects are working. I thought maybe it has something to do with the composer.json autoload array so I have tested that and nothing. Not a jot. Either I'm being thick or there is something fundamental which isn't being explained in the docs. I'm running the latest version of laravel. Any ideas?
Laravel changed the folder structure with its latest release (which is version 5):
In 4.2: app/routes.php
In 5.0: app/Http/routes.php
There's also a few things you need to do in order for a Laravel Project to work. First (and this is the method I use) create a symbolic link to your project's public folder:
ln -s /path/to/webroot/example_app/public /path/to/webroot/example
Next, change the permissions on your storage folder:
chmod 777 -R storage
You should now be able to access localhost/example and the Laravel 5 welcome page should show up. Usually I call my project example_app and create a link to a folder called example, so I can easily access it via localhost/example
In Laravel 5, the routes file is located elsewhere: app/Http/routes.php.
Basically I did chmod 777 on the storage and vendor files and it started working
I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.