How to embed a Laravel application within another web application? - php

So I have a web application, say www.randomwebapp.com, and I want www.randomwebapp.com/laravelapp to point to a laravel app I have written. I've already figured out how to include my laravel app as a separate package and access classes within my laravel app, but I'm wondering how to actually go about rendering views/routing etc. I'm mainly concerned with how to actually start running the app (perhaps something to do with bootstrap/app.php or bootstrap/autoload.php).

I'm assuming you're using the boilerplate laravel installation folder structure provided by https://github.com/laravel/laravel, and your two apps are truly separate and have no dependencies on each other.
I'm also assuming folder structure looks something like this:
+ /webroot
+ /app
+ ( other laravel folders )
+ /public
+ /vendor
+ index.php
+ /other-site-dir
I would simply rename public to laravelapp. You may have to edit your laravelapp/.htaccess (formerly public/.htaccess) file to not redirect to your domain root and direct to laravelapp/index.php instead.
You may also have to rewrite our group all your routes into a Route::group('/laravelapp'...);
These are just off-the-cuff thoughts... If you have an example of your folder structure, it could help.

Related

Access Core PHP folder inside a Laravel 8 project

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.

Angular 2 + angular-cli + Laravel 5.3

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.

How to set up references between twig file and assets files(CSS, Js) in Silex?

Before I start I want to say that I am new to working with this framework and some of its features I do not fully understand.
So, I have the following structure:
Desired assets folder location:
web
assets
css
file.css
Current twig views location:
src
App
views
file.html.twig
So the "web" and "src" are on the same level. Now how can I link the CSS for the "file.html.twig"? I also read the Silex cookbook (http://silex.sensiolabs.org/doc/cookbook/assets.html) but I don't quite understand where do I have to write every step presented there. Thank you.
The app.request.basepath is a link the base path of your application, e.g. the public (accessible) php file where you instanciate and run you Silex application.
Mine is an index.php in /web, so writing {{ app.request.basepath }}/assets/css/file.css is OK and leads to 'web/assets/css/file.css', but my guess is thaht you did not put your main index.php file in /web directory (maybe in a sub-directory). You should check that first.
I'm quite new to Silex as well so you should take my words with caution, but taking a look at it doesn't cost anything after all ;)

config codeigniter to run first project

I am using xampp and my document root in apache is set to htdocs directory by default. I download Codeigniter and unzip the project into this directory. It runs fine. Now I would like to use CI to create my own project. In the controllers folder I would like to create a folder named “myproject” and in the views folder of application folder, I would like to create a folder named “myproject_view” in which I will store all of my view files. My problem is I don’t know how to reset my config file (especially the route.php) for my project to work then.
CodeIgniter documentation doesn’t have a section to specify how to do this, the information given in URI Routing chapter is not enough for readers to understand this at all. Plus, What if I also would like to store my controler files in a nested folder (controllers > somefolder > someanotherfolders > etc) ? Thank you very much.
[UPDATE]
If you only leave all controller in controllers folder, and view files in the views folder, then things work out easily, what if you create a folder in teh controllers and a folder for view in the views folder. I guess you need to change your default route configuration. I would like to know HOW ?
CodeIgniter's documentation covers Sub-Folders for Controllers.
Views on the other hand, are always loaded from controllers. Therefore, you can write:
$this->load->view('my_folder_name/my_view');
Routes are not required here.

How to generate urls without pathname in a Symfony project

Using a routing rule in a Symfony project the function link_to (or url_for) generates an url like mydomain.com/myproject/web/friendly-name.html or mydomain.com/web/friendly-name.html
There is a smart way, alternative to write own helper, to generate urls without /myproject/web or /web keeping the choosen directory structure.
Updating
Finally I found the solution in the answer to this question: symfony on virtual host document root problem
just point your webserver Document Root to /web Directory.
This is the right way of integrating symfony1.4.
Cheers malte

Categories