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.
Related
I still want my codes in public directory, and since I have to use the school's computer, I can't make the URL from localhost to something else.
Example: whenever I type URL for href, I have to put it like this. (larsamp is my project name, posts are the param)
About
But I just want to type this instead
About
Here is the routing PHP:
Route::get('/about', 'PagesController#about');
I found some solutions, but they do not work.
Change public directory to shorten the public part: I have another directory called private to store many things else.
Create a global variable (i.e. $u) and put it in the layout directory: but I have many layouts.
Overload href or make a function inherit href and use it instead: my teacher said that will make my program too complex. Not good.
In conclusion, a way to shorten URL without making the program too complex and can be used on a school computer (no changing host.txt)
You can use the url() helper which returns a fully qualified url:
<a href="{{ url('about') }}>About</a>
https://laravel.com/docs/5.8/helpers#method-url
Alternatively there is also the route() helper:
Route::get('/about', 'PagesController#about')->name('pages.about');
<a href="{{ route('pages.about') }}>About</a>
https://laravel.com/docs/5.8/helpers#method-route
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 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') }}
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.
Is it possible to add an extension to laravel routes like so?
http://www.mywebsite.com/members/login.html
and another page with a different extension
http://www.mywebsite.com/contactus.htm
I am transitioning an old website into laravel but the owner doesn't want to change the URL for SEO purposes.
Yes, this is certainly possible and very straightforward to do with Laravel.
routes.php:
Route::get('members/login.html', function() { return View::make('members.login'); } );
Then you need to create the view members/login.php or members/login.blade.php in your views directory.
Route::get('{id}-{another_id}.html', 'Controller#view')
->where('id', '.*?')
->where('another_id', '\d+');
Something like this