Laravel localization with Voyager admin - php

I'm making a Laravel website with Voyager admin and now I need to add localization to that website. Voyager includes its own translations table and I'm using it for creating content in multiple languages from backend. But in the frontend routing is not working, I'm getting NotFoundHttpException error. My routes are as following:
Route::group(['prefix' => 'fr'], function()
{
App::setLocale('fr');
Route::get('{slug}', 'PageController#show');
Route::get('posts/{slug}', 'PostsController#show');
//and so on
});
How can I fix this?

According to the documentation you can go
Route::prefix('admin')->group so
Route::prefix('fr')->group(function()
{
App::setLocale('fr');
Route::get('{slug}', 'PageController#show');
Route::get('posts/{slug}', 'PostsController#show');
//and so on
});
AND also the order is important.

Related

Laravel 5.5 Routing and Sub-domain Routing

I am very new in Laravel. I currently created my personal site on Laravel 5.5 and uploaded to GoDaddy server: http://bhattraideb.com/. Now when I click on 'Blog' from navigation I would like to redirect like http://blog.bhattraideb.com/ which is currently redirection to 'bhattraideb.com/public/blog'.
Again from the same this link 'bhattraideb.com/public/blog' when I click on 'Resume' I aspect to redirect on 'bhattraideb.com/'
Here is my route code
//** Resume Routes
Route::prefix('/')->group(function() {
Route::get('/', 'Frontend\ResumeController#index')->name('resume.index');
Route::resource('resume', 'Frontend\ResumeController');
});
//** Blog Routes
Route::get('show/{id}', 'Frontend\PostController#show')->name('post.show');
Route::get('blog/{slug}', ['as' => 'post.single', 'uses' => 'Frontend\PostController#getSingle'])->where('slug', '[\w\d-\_]+');
Route::resource('blog', 'Frontend\PostController');
Can anyone please guide me for this.
Thanks in advance.
You can read up on https://laravel.com/docs/5.5/routing#route-group-sub-domain-routing for more details on this but the following simple example should work:
web.php
Route::group(["domain" => "blog.bhattraideb.com" ], function () {
Route::get("/", "Frontend\PostController")->name("blog.index");
//All blog routes should be defined in here
});
You can then use the helper route("blog.index") to get the URL along with the subdomain when generating links to the blog.
Note that you will need to setup the webserver to accept blog.bhattraideb.com as an alias of bhattraideb.com. Laravel will then sort the rest out

Create new folder from public and use as a admin side in laravel

I'm new to laravel so if my question is not up to the mark then forgive me but I googled it and not found answer as per my requirement.I follow https://laracasts.com/discuss/channels/laravel/setup-different-frontend-backend-endpoints-in-laravel-51 && https://laracasts.com/discuss/channels/general-discussion/splitting-admin-and-front-end
MY NEED :
I want 2 entry point for my laravel application. one is for front user and second for admin user.
I am using laravel latest version (5.3.26).
As we know public folder is the entry point for laravel application.
Ex : http://localhost/news_report_old/public/index.php
Using above URl we can enter into application. Right ?
Now I want to create new entry point for Admin So I thing I can copy public folder and rename it so my work is done but I missing something and I can't figure out what I am missing ?
EX : http://localhost/news_report_old/admin/index.php
So when I open above URL I want to open Admin side.
How can I achieve this ?
Thanks.
You, don't need to copy public folder. That is terrific idea. (Don't ever mess with core/structure framework code, unless you have no any other option)
You can distinguish front end and admin panel easily using router and middleware.
You should create a custom middelware:
https://laravel.com/docs/5.3/middleware
And routing can be like:
routes/web.php:
// List of all front end routes:
Route::get('/', 'ArticleController#index');
Route::get('/home', 'HomeController#index');
Route::get('/about', 'HomeController#about');
// List of all admin routes
Route::group(['prefix' => 'admin', 'middleware' => 'admin']], function () {
Route::resource('admin', 'AdminController')
});

Laravel: Get current params in routes.php

I'm using the extension laravel-menu in my Laravel application.
This application contains multiple projects with multiple locations attached to each project.
Now I want to define a sidemenu where I can among other manage the locations.
The url of a project is
project/1
The url of the locations page of a project is
project/1/locations
How to setup this side menu in routes.php?
My routes.php code:
Route::resource('project', 'ProjectsController'));
Route::resource('project.locations', 'LocationsController');
Menu::make('sidemenu-project', function($menu) {
$menu->add('Locaties', array('route' => 'project.locations.index','{project?}'))->data('id',1); // this is not working
});
This is outputting the url /project/%7Bproject%7D/locations
Go to your terminal (Command Prompt) and run following command:
> php artisan routes
Then you'll see all the declared routes with their URL and corresponding route name and method name.
I'm very new to Laravel but the Routes page of documentation mentions you create a controller with parameters like this:
Route::get('user/{id}', function($id) { ... });
could you therefore define your route as
Route::get('project/{id}/locations', function($id) { ... });
I think you have this issue due to misconfiguring the routes. To achieve the route structure that you want, you should put your project/1/locations route definition above the first one. Consider your routes.php to be:
Route::resource('project/{project}/locations', ['as'=>'project.locations', 'uses'=> 'LocationsController']);
Route::resource('project', 'ProjectsController'));

Laravel, use auth and auth.basic

I've got a website with an 'admin dashboard'. I would like to limit access to the admin dashboard with the auth.basic filter in Laravel.
But the site itself also has an account system, and I would like to use the 'normal' auth filter for that.
Is it possible to use those two filters seperate from each other, but on the same website?
Use groups and define other routes inside them.
Route::group(['prefix'=>'admin', 'before'=>'auth.basic'], function(){
Route::get('/', function(){});
});
Route::group(['prefix'=>'account', 'before'=>'auth.account'], function(){
Route::get('/', function(){});
});

Admin Routes (or Prefix Routes) in Laravel 4

How can I create admin specific routes in Laravel 4 (Restfull Controllers):
/admin/users (get - /admin/users/index)
/admin/users/create (get)
/admin/users/store (post)
I want to know:
What Files and where I need create theam
How I need create the route
In Laravel 4 you can now use prefix:
Route::group(['prefix' => 'admin'], function() {
Route::get('/', 'AdminController#home');
Route::get('posts', 'AdminController#showPosts');
Route::get('another', function() {
return 'Another routing';
});
Route::get('foo', function() {
return Response::make('BARRRRR', 200);
});
Route::get('bazz', function() {
return View::make('bazztemplate');
});
});
For your subfolders, as I answer here "route-to-controller-in-subfolder-not-working-in-laravel-4", seems to have no "friendly" solution in this laravel 4 beta.
#Aran, if you make it working fine, please add an code sample of your controller, route, and composer.json files :
Route::resource('admin/users', 'admin.Users');
or
Route::resource('admin', 'admin.Users');
thanks
Really useful tool that you can use is the artisan CLI.
Using this you'll be able to generate the needed function file with all the required routes for it to become RESTful.
php artisan controller:make users
Would generate the function file for you. Then in your routes.php file you can simply add
Route::resource('users', 'Users');
This'll setup all the necessary routes.
For more information on this you should read the documentation at.
http://four.laravel.com/docs/routing#resource-controllers
http://four.laravel.com/docs/artisan
Edit:
To make this admin specific, simple alter the code like follows and move the controller to a admin folder inside the controllers folder.
Route::resource('admin/users', 'admin.Users');
The first paramater is the route, the second is the controller filename/folder.
In Laravel if you placed a controller inside a folder, to specific it in a route or URL you'd use the a dot for folders.
You can then expand on this and add Authentication using Route Filters and specifically the code found "Pattern Based Filters" found on the page below.
http://four.laravel.com/docs/routing#route-filters
Laravel 4 - Add Admin Controller Easily
This was driving me insane for ages, but i worked it out.
routes.php
Route::resource('admin', 'Admin_HomeController#showIndex');
/controllers/Admin/HomeController.php
Notice the folder name Admin must be captital 'A'
<?php
class Admin_HomeController extends Controller {
public function showIndex() {
return 'Yes it works!';
}
}
Alternatively you can use the group method
Route::group(array('prefix' => 'admin'), function() {
Route::get('/', 'Admin_HomeController#showIndex');
});
Thanks
Daniel

Categories