I would like to know how can I call all my scripts file inside /public/bower_components in laravel? I'm having problem with the loading of all my scripts since we are also using a loadbalancer. Here's a sample of my code
URL: http://10.0.2.3/transaction/ <---- my project url where 10.0.2.3 is our loadbalancer/haproxy public IP and 'transaction' is the keyword use to reroute to our private server.
Now when I use this laravel script
{{ Html::script('bower_components/angular/angular.js') }}
I assumed that this will look for the angular.js file in the url
http://10.0.2.3/transaction/bower_components/angular/angular.js
but upon checking my file its looking in this url
http://10.0.2.3/bower_components/angular/angular.js
as you can see the keyword 'transaction' is removed. Is there a way to fix this so that it will look for the file in the correct path with 'transaction' included in the url?
You can just write a custom helper to prepend the route
if(! function_exists('asset_lb') {
function asset_lb($path) {
return asset('/transaction/'.$path); // <--- you need to customize the PATH Separator.
}
}
then use in project
{{ asset_lb('bower_components/angular/angular.js') }}
Related
I have a file inside my storage folder.
Located path :
storage/app/public/$/10012940/gallery/289sdas98e.jpg
$, 10012940 and 289sdas98e.jpg is dynamic and can change.
Route::get('storage/{$folderDirectory1}/{$customerReference}/gallery/{file}', function ($filename)
{
});
Since its a nested folder I cannot find much on internet as to what the route should look like. Also how to go about doing something like that.
I am trying to find a way to access this path via the route so that I can write a middleware to authenticate before making this accessible to the end user.
I am storing the file inside the storage folder due to the visibility. I would like to control who should have access to viewing the image
You should use a route name.
For instance, in your view: href="{{ route('assets.show', $asset) }}".
In your AssetController#show, simply return Storage::download($asset) for instance.
Then use your middleware to authorize or not the access to the show method.
Hi I'm coming for a very simple question (I think) but i didn't found the answer or a similar case.
I'm using symfony 3 and trying to build a second menu for my administration pannel.
However, I have a problem about how I have to declare the relative url in my "href", For my main menu i used to do like this
{{ url ( 'admin' ) }}
and it worked. The fact is that now I have subfolders and many levels in my url.
The url i try to reach is myapp/admin/gameadmin, this url work when I'm going on it but when i try to put it in 'href' I have an error message which says that the route is not working.
i declared it like that ->
{{ url(admin/gameadmin) }}
I tried with different character -> admin:gameadmin, admin\gameadmin ... etc and with path instead of url i don't know if it's not the good way to declare it or if I have a problem with my controllers.
In my bundle it's organised like that :
->Controllers(folder)
->admin(folder) (You can also find my main controllers on this level)
->admingamecontroller (Where the page I try to reach is routed)
I hope i gave you all the informations, thank you for your help and sorry for my english !
The url parameter is not the the url per se (ie: admin/gameadmin), this is the route name, defined in your routing.yaml file, or in your controller annotation.
If your action is something like this:
/**
* #Route("/admin/gameadmin", name="gameadmin")
*/
public function gameAdminAction()
{
...
}
Then, to generate the route, you have to do this:
{{ url('gameadmin') }}
By doing this, all the links on your website will be up to date if you change the gameadmin url, as long as you don't change the route name.
I suggest you to read this documentation on the Symfony website: https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/routing.html
Edit: As pointed by user254319, if you're not using annotations, you'll have to edit your routing.yaml config file.
gameadmin:
path: /admin/gameadmin
controller: App\Controller\Admin\AdminGameController::gameadminAction
The route name is the yaml key: gameadmin.
Related Symfony documentation: https://symfony.com/doc/current/routing.html
I have route defined in my route.php file like below:
Route::get('{test1}/{test2}/{test3}', function($test1, $test2, $test3) {
$result = [$test1, $test2, $test3];
return view('view', compact('result'));
});
it works fine in my controller but on the view part when i see it in the browser when i just write something like this in browser:
http://localhost/mysitefolder/public/test1/test2/test3
it loads the view and pass all the data but it gets all of my assets like my stylesheets, images and scripts from a url like below:
http://localhost/mysitefolder/public/test1/test2/js/jquery.js
why is that happing?
thanks in advance!
Two solutions either use a / in the start of your URLs so that relative addressing is not used or use laravel's helper functions {{ asset('/js/script.js') }}.
When you do not use '/' in the beginning your url, it is treated as if it was a relative address and current location is added in its start.
Sometimes even '/' won't work if your application is not served on Root level. For example you have your application at http://localhost/yourapplication then / would refer to your localhost instead of application, that's why best way is to use laravel's helper function.
Apologies in advance if this is a noob question
I have a delete function in Laravel, I am having problems with the route and returning variables I need when the website is hosted externally.
I currently have the URL coded like this
Delete</td>
I would like this url to be dynamic. I have tried the public_path() function but have had no prevail.
Delete</td>
Thanks
You should use the routing system to generate urls ,and not create them by hand, it's quite easy:
http://laravel.com/docs/routing
the concept is simple:
1) create a route in the routes.php file
2) use it with the route() helper
edit:
to use a route and let LARAVEL generate the correct url , you simply have to do something similar to this (supposing that you are using blade):
Delete
You can use url() for example, like this:
Delete
You can also call link helpers:
{{ link_to('safesign_doc_delete/'.$file.'/'.$sector_name.'/'.$selected_sector, 'Delete') }}
url() is the default helper function get your hosting url which is found in the app.php under 'url' => 'http://localhost' (or other)
This will solve your URL problem
NOTE
if you are worried about changing it when it goes to production don't worry.
Laravel gives you folder options where you can have LOCAL as a folder with localhost as your url and then the main app.php file can be your production settings.
I have am using Laravel and I am trying to call a single php file via the browser, which is
located in my app path.
I have setup a Route::get to a function HomeController#index
function index(){
include(app_path().'/myphpfile.php');
}
And gets called when doing http://localhost:8888/home/index
This is how I call it atm.
The Problem is my file accepts furthe parameters, which are
processed inside my php file like:
http://localhost:8888/myphpfile.php/user/hello1
or
http://localhost:8888/myphpfile.php/user/hello1/default
So I tried to use Route::any.
It is not working. Can I somehow just tell Laravel to pick up the php file like I mentioned above? Other way then using include?
I donĀ“t want to put this file into the public folder.
Something like wildcard routing.
Thank you for your help.