I have a webshop in laravel and always when I load the page the app.js make an ajax request with the same url. My app.js resource file is empty so I think this is a laravel function. Any idea why make the laravel this call and how can I turn off?
I think it is okay, because all your js and css files must be loaded from server tr
and app.js are not exceptions ))
Related
I have made a basic Laravel project and had configured my api.php file to have a GET route when I want to fetch data for my project, but whenever I try to load the data on browser or perform a GET on the link (localhost:8000/data) from postman, it shows Error 404 Not Found. It seems that the GET is not able to find the URL that I had mentioned above. How can I get this issue sorted?
Not 100% sure this applies to you from the question. But Laravel prepends /api/ to API routes by default.
Maybe try requesting from localhost:8000/api/data?
I create company profile website using laravel 5.8 and vue js for make it reactive, it's not SPA(single page application) maybe we can call it hybrid, everything run well in local, after i modify javasacript locally then run a command yarn watch to compile and run my web again it runs well. let's say i have uploaded my project to shared hosting. then i modify my javascript code then re-upload my app.js code and here's a problem. the browser loads my previous app.js not my new app.js. i have cleared browser cache it's sill load the previous app.js. how to solve this problem?
thanks
put a random number at the end of address like this:
<script type="text/javascript" src="app.js?v=12392823"></script>
Better option is to add .version() to your webpack mix file:
mix.js('resources/js/app.js', 'public/js')
.version();
After that, when you call mix('js/app.js') in your view, it will add the cache busting get parameters automatically and the parameter will ONLY change if the file has been changed.
I am in the process of installing SimpleSAML and in the php library, there is a folder called www that has index.php. According to the docs, there is an admin console within it. However, at the moment I am unable to access it via the url www.website.com/third_party/simplesaml/www/index.php.
I am supposed to use the admin console to generate some metadata so I'm just wondering if it is possible to route to a view from there?
I'm thinking that I create a controller and just hard link $this->load->view('url to www') but I'm not sure if that works.
In controller’s constructor add
include APPPATH . 'third_party/simplesaml/www/index.php';
to include the file in your project.
you can set base path in route file and instead of $this->load->view() you can use renderView() function to access view in codeigniter.
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 am just trying to host a laravel site to production. There is an error with the routing all my css and javascript files are being treated like a route instead of files and they are not loading
<script src='http://project.com/project/assets/js/jquery-1.9.1.js' type='application/javascript'></script>
I can see that this html is generated but the files are not being loaded When I click on the link I get a NotFoundHttpException
This is wroking fine in my local machine. This error is present only in live server.
Thanks in advance!
The src link to your js file is set using Laravel's HTML::script()? If not change it because this will help so that you can have proper full urls for js and css files. So if you have a js file like public/assets/js/custom.js you should call it like this:
{{ HTML::script('assets/js/customs.js') }}
and you will be fine. Just remember that your starting point for assets is inside public folder. HTML::script() or HTML::style() get you there at once.
It turns out the issue is with nginx configuration. The root folder to the server was set incorrectly. So it was looking for differnt files. Not a code issue just and issue with the server environment