run independent .php inside laravel framework - php

I recently installed laravel framework in my laptop.I installed laravel in my Xampp server's htdocs/laravel/laravel source path
How can I run execute written PHP codes normally in browsers and run execute them out side laravel framework?
That means if I create a new .php file in desktop that will show "hello world". Where I should keep that file or in which folder to show my this individual file run in browser only inside laravel framework.

You can put it inside your public directory. If your application has a domain of localhost you can access it via localhost/script.php. BUT this is extremely ill-advised as you are opening yourself to potential vulnerabilities depending on what your script does.
If it is for testing then fine. Otherwise you will have to put that somewhere in your application say app/scripts/script.php where it cannot be accessed via the browser (the only point of stand-alone scripts in web application is for CRON tasks or for CLI commands). If this is the case, you may want to take a look at http://laravel.com/docs/4.2/commands about writing your own artisan commands.

Simplest solution in make filename.blade.php file.
put it in resources/views/filename.blade.php and execute it using routes routes/web.php
Route::get("/filename", function(){
return view('filename');
});

I would recommend storing that code in a custom library inside of Laravel and including it within a controller.

You can put your PHP file inside your storage/app/public/filename.php folder in your laravel application folder and can run like
your_domain_name/storage/filename.php

Related

Working with php files using webpack

I'm working on project using React on client side and PHP on server. I'm building client using webpack but my problem is that I'm not sure what's the right way to "import" .php files. I want to post to them using axios, so I need to know their place in my project structure. But if I run "webpack" my files will land in /dist folder. For example from component the path to php file would be "../../dist/php/getItem.php" but after webpacking it will change.......
How can I make some kind of special folder for php files, that would be available for me before as well as after building my components? I've found "file-loader" for webpack but I can't find any example of using it for php files.
I hope I explained my problem

Laravel routing intercepts all requests to js files etc

I'm new to Laravel and I've been having a few problems setting up the dev environment for Laravel.
I'm using the Built in PHP web server on windows. Which I've started either with:
php artisan serve
or
php -S localhost:8000 server.php
I'm basically trying to get css and js served correctly, unfortunately the Laravel routing seems to be getting in the way. I initially rewrote the server.php file to not run on requests ending in .js, css etc.
However this requires me to suffix any src URLs with public which is not really sensible.
I've seen quite a few tutorials about how Laravel Elixir writes the SASS and minified js files to the public folder which looks perfectly fine but I can't get past this routing issue.
What am I missing? I've seen very few details about this so not sure what I've done wrong here.
Note I'm trying to get this working so a dev team can use this so ideally I'd like to avoid complex aliases etc. Which could easily be setup in a live environment but in a team it becomes painful and I can imagine people being tempted to hack the server.php file or similar horrors.
Thanks,

How does Laravel Artisan created php files with properly formatted lines

This is just a general question, how does Laravel Artisan able to create proper .php file e.g. make:controller with the correct formatting and line breaks?
Is there a good PHP script which can help one develop similar php codes.
Thanks
Ultimately, Artisan relies on Shell scripts included with Laravel. Which are written in the language of Shell and reside in files ending with the extension .sh. Here is a website that contains more explanation of what those are and how to develop them: https://www.shellscript.sh/ If this is ever unavailable simply searching "How to create a shell script" will get you the answer.
PHP can execute these scripts, for example, when you visit that PHP page in your browser, or you trigger it from the command line, assuming you have PHP installed on your server.
Artisan, is custom built to allow you to extend it with more commands, and there are tutorials available to show you how to do that, but it's a completely separate process from creating custom shell commands.
PHP files are just text files, you can easily create them with any language. Also in Laravel usually used so called stubs, templates for classes like migrations, controllers etc.
Just go and look how as Laravel does that under the hood.

Run Silex from subdirectory nginx, no config access

I have an older PHP project on a customer server, with no access to the config files, the server is runner nginx, and PHP 5.4 ...
Is there a way to use Silex Framework or another modern PHP framework from a subfolder? .. e-g. example.com/silexproject/ without access the .config file for the webserver?
is there an nginx alternativ to .htaccess ?
A quick google serach, shows that no, there is not an .htaccess like file for nginx. Quoting the official wiki:
Stop using .htaccess. It's horrible for performance. Nginx is designed
to be efficient. Adding something like this would destroy that.
Keep in mind that you can still use Silex (I imagine that you can use any modern PHP framework as well) you just need to remember to call the front controller every time (so your URLs won't be that pretty).
For example if your project is on http://example.com/projectdir/ your front controller most likely will be http://example.com/projectdir/index.php and if you need to access some resource under that path, you'll need to type http://example.com/projectdir/index.php/path/to/resource (notice the name of the front controller in the URL)
My advice is that you'll try to contact whomever has access to nginx config file and ask if they can change the nginx config.

Run PHP scripts stored inside Rails directory structure

I built a PHP application using Drupal and I want it to run under the same domain where Rails is running. So for example I have mysite.com running on Ruby on Rails, I would like to install and run Drupal in mysite.com/my_drupal_application.
I tried creating a subfolder inside rails , on the same level as apps and models directories but that did not worked. I tried moving creating a subfolder in the public directory too but it didnt worked either.
Maybe rails is confusing the url to be calling a controller? So what else should i do then?
Thanks a lot!
Both Drupal and rails have their own routing logic. Drupal stores it in both the database and the hook_menu, rails has it defined in the router.rb. They will conflict at some point.
So, the advice is to run your Drupal app on either a different subdomain, defined in a virtual-host. Alternatively you can define vhosts that define urls where your rails and Drupal app run. You should run them next to one another, and never inside one another.

Categories