Laravel routing intercepts all requests to js files etc - php

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,

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

the phonegap directory structure in apache php

I am sorry for this such question as I am still a fresh beginner in Phonegap.
I have followed some tutorial both for the installation and the jquery.mobile usage.
There are some parts (the biggest part) that I am confused with this Phonegap. And it is about the directory structure.
I am working with Private PHP Framework from my department, that is why I used Lamp Stack for all of this.
However, with the Phonegap tutorials I have been following this far, it looks like it have a little bit different environment structure from usual. It have five default directory as follows:
Hook
platforms
Plugins
www
In where the working directory for this Phonegap must be in the www directory.
It makes me afraid because our Apache Environment require us to put the directory in costume folder (Not in var/www), and then also the PHP Framework require us to put the module in a specific folder.
Please, I just need an enlightment for this Phonegap, how do you access the files and where do you guys put it.
Many thanks in advance.
As requested:
Create another vhost that points to www. You don't need to worry about hook, platform and plugins which are cordova/phonegap folders. Let them all at the same level (don't change the structure, just point the vhost to www).
The structure of cordova/phonegap is simple. Inside the www folder will be all your programming logic to build yours mobile app.
But beware, the cordova/phonegap does not compile code in PHP, it just uses a webview (like a browser) to run your mobile application developed with HTML, CSS and Javascript, packaged in a apk with access to native features of the smartphone/tablet, basically.
To make your application to communicate to the server in php you have two alternatives:
1) Making your app to access a URL that points to the application
developed with PHP and render its application in webview.
2) Create all purely on HTML, CSS and Javascript and make
communication via ajax, or socket or something similar to the server.

run independent .php inside laravel framework

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

How to use grunt-usemin in PHP projects?

All the tutorials on optimizing website assets with grunt and grunt-usemin are based on the src -> dist deploy strategy. basically processing the items in your src folder and compiles them into the dist folder.
But PHP doesn't work this way. It isn't compiled and "distributed". The source and target page are the same. Which makes it a destructive process.
How do you work around this? Any tips on using Grunt in PHP project in general?
Thx.
We do something similar. We created an index.src.html with the non-minized sources, and create an index.html from this file using usemin, and we have a "proxy" php file which opens the index.html if it exists (which means we are in the production environment and the assets are built), otherwise the index.src.html if the assets haven't been built or we are in a development environment. The main idea is to separate the important parts for usemin to a different file.
The usermin plugin is for preparing static assets (concatenate, minimise,...). Static means the server gives the same content for everybody. This constraint doesn't apply to PHP...
If you would like to use this tools to optimize your php generated pages assets, you should create input files which can be parse-able by usermin. For example you can collect the javascript/css file references into a template or a different php/html, and you include/use this file where you need, and after the build you use the usermin parsed version of it.
The ideal approach would take advantage of the dynamic nature of PHP to make the "distribution" URL replacement. The process would be:
Your build tool creates some kind of manifest or machine readable file with changes applied. Some tools, as gulp-rev will do this for you.
Read the manifest from PHP and replace the resource URLs with the final ones.

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