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
Related
This may be a dumb question, but I've started exploring Laravel Breeze with vue and I'm not sure how to manage resources and their views. (Using Laravel 9)
For example, if I have a table 'members' and a resource controller 'MemberController', ordinarily in the web.php file I would do something like:
Route::resource('members', MemberController::class)->names('members');
Then I'd create a 'member' folder in my resource/views folder to store the views for that table. I could then call the view from the MemberController something like:
public function index()
{
$members = Member::all();
return view('member.index', compact('members'));
}
I'm trying to do something similar using vue in breeze, so I guess I'd have the vue pages in the 'resources/js/Pages' folder. But this didn't seem to work properly.
I don't know how to transition from the previous approach of handling resources and views to Breeze using vue.
What's the recommended way to handle resources in an SPA with Breeze/vue?
After following Djave's suggestion, I took a look at the sample app from inertia.js and that answered everything.
The problem I had was due to using the dot notation when specifying the path to the vue page. So, in my example above, it should instead be like this:
return view('Member/Index', compact('members'));
The inertia sample app code has a lot of good examples!
I have been invited to collaborate on a laravel 7 project and I have been able to set up the project locally on a windows 10 system using wamp server. While reviewing the project, I noticed the plan is to use subdomain routing. I am currently tasked with setting up the blade templates and I want to test the route but I can't get the route to work correctly even though the routes exist. This is what the routes look like
When i try viewing the page for realestate by calling the url like this realestate.localhost:8000 I get the connection error below
The route is inside routes/realestate.php folder and its using a closure
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return 'Realestate Routes';
});
What is the right way to call the route in my local enviroment on windows?
I'm not sure if your environment is different from mine, but make sure you're accessing via http:// and not https://
I just saw your Route code - it's been a long day, sorry :P
Try reading up on Subdomain routing here.
Your Route should look like this:
Route::domain('realestate.localhost')->group(function () {
Route::get('/', function () {
return 'Hello, world!'
});
// all other routes for realestate.localhost go in here
});
You need to edit your hosts and add redirect to localhost from your subdomain. see https://stackoverflow.com/a/56921347/11775360
I have experience using .htaccess files to redirect user requests from one place to another. However, I am new to Laravel and have never attempted to do redirects in Laravel.
What's the best way to do redirects in Laravel? Is it as simple as putting an .htaccess file in the project root and doing things like I normally would, or does Laravel have a special way of doing this?
For my specific use case, I want to redirect requests to images in an img directory to another publicly accessible path.
Thank you.
Laravel has a helper function for redirects, here are some examples:
Route::get('dashboard', function () {
return redirect('home/dashboard');
});
or from inside of an controller action:
return redirect()->action('HomeController#index');
Official Laravel Redirect Documentation
Everything is available at Laravel Documentation but you need to look at it. In your case you can use global redirect helper:
Route::get('route', function () {
return redirect('anotherRoute');
});
So basically my site was pre-made so that pages did not exist. The only features that existed was a directory and some posts. No pages. So I had to duplicate the posts function (meaning I replaced all instances of $post and $posts with $page and $pages). It all worked fine. I created a test page which worked. But now I can't access my backend.
This is the URL structure of the pages as seen in the routes file:
Route::get('{url}', 'postsController#viewpage');
So it will basically look like this: www.mywebsite.com/pagehere
But the backend's URL structure looks like this: www.mywebsite.com/admin
So I wonder if my page structure is conflicting with the admin backend?
Whenever I try to access the backend, I get redirected to the homepage.
My controller file has this:
public function adminpage(){
return view ('admin/index')->with("title","Admin");
}
Seems like the rule you put in place matches every route:
Route::get('{url}', 'postsController#viewpage');
You need to specify that the given url must exclude routes tarting with admin, via a regex you can achieve this:
Route::get('{url}', 'postsController#viewpage')->where('url', '[^admin]');
Also I would advise you to use appropriate naming convations: PostsController
Laravel route regex docs
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.