How can I do like the following route which is in codeigniter in laravel 4 or 4.1? - laravel-4

My current website is in Codeigniter: http://www.tenders.af I want to convert it to
Laravel 4.1
I faced this problem with routing and I could not solved it yet any help will be appreciated.
my routes in codeigniter:
$route['afghanistan-tenders/(:any)'] = 'home/details/$1';
how can I write like the above route in Laravel 4 or 4.1

Route::get('/afghanistan-tenders/{id}', ['uses' => 'HomeController#details']);
Then in your HomeController
public function details($id)
{
echo $id;
}
Edit: based upon your comment below - can you just do this?
Route::get('/afghanistan-tenders/{id}/school-development', ['uses' => 'HomeController#details']);
or
Route::get('/afghanistan-tenders/{id}/{name}', ['uses' => 'HomeController#details']);

Related

Can't seem to find a way to use the route.php from 5.2 from laravel 5.2 to 8.83.25 web.php

I'm pretty new with Laravel, was able to work on finding a tutorial but it uses a
5.2 version.
I'm trying to convert the older version to 8.83.25
This is the route in the tutorial that I'm following.
I have created the CategoryController.php manually
Route::group(['middleware' => ['web']], function(){
Route::get('category', 'CategoryController');
});
What you used is wrong syntax. To pass a route to a controller, you are supposed to pass it as an array as such:
Route::group(['middleware' => ['web']], function(){
Route::get('category', [CategoryController::class]);
});
Now supposing you want to pass it to a particular function(lets say the function store) in your controller, you just indicate that in the array as such:
Route::group(['middleware' => ['web']], function(){
Route::get('category', [CategoryController::class, 'store']);
});
Take a look at the docs to learn more about laravel v8 routing.

Backpack 4.1 Routes syntax

I'm updating Laravel 5.4 to Laravel 8, so far everything goes "well" it's time consuming but the upgrade worth it.
My problem is that I don't know Backpack very well and the upgrade is considerable.
I'm now stuck with the new route syntax, there where a CRUD::resource facade that handled route customization that is not available anymore.
What would be the right approach for the following "simplified" custom route files. (I removed everything I figured already)
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => [
'web',
config('backpack.base.middleware_key', 'admin'),
],
'namespace' => 'App\Http\Controllers\Admin',
], function() { // custom admin routes
Route::get('report', function() {
$clients = ClientWithSubscription::get();
$clientsT = transformer()->transform($clients);
return view('clients')->withClients($clientsT['data']);
});
// Client
CRUD::resource('client', 'ClientCrudController');
Route::group(['prefix' => 'client/{client_id}'], function() {
CRUD::resource('address', 'ClientAddressCrudController');
CRUD::resource('subscription', 'ClientSubscriptionCrudController');
});
// Taxonomy
foreach (['theme', 'tag', 'subject', 'utility', 'document_type', 'special_need', 'level', 'platform', 'other', 'shop',] as $taxonomy) {
CRUD::resource('taxonomy/' . $taxonomy, 'TaxonomyCrudController');
}
// Items
CRUD::resource('item/document', 'ItemDocumentCrudController');
// Referrals
CRUD::resource('referrals', 'ReferralCrudController')->with(function() {
Route::post('referrals/mark-paid/{id?}', 'ReferralCrudController#markPaid');
Route::post('referrals/mark-unpaid/{id?}', 'ReferralCrudController#markUnpaid');
Route::post('referrals/edit-notes/{id}', 'ReferralCrudController#editNotes');
});
});
My questions are
How do I add a prefix to all crud route ?
If a CrudController use default route, then it mean I don't need to declare it at all, Backpack will take care of it ?
How do I add custom method to the CRUD Route ?
Thank you!
Two changes are needed:
instead of CRUD::resource('item/document', 'ItemDocumentCrudController'); you should now do Route::crud('item/document', 'ItemDocumentCrudController');
the extra routes inside the ->with() closures should be moved after the appropriate Route::crud() statement;
See this step in the Backpack upgrade process for more details.
Also, make sure to upgrade to Backpack 4.0 (using its upgrade guide), and only after it's working to upgrade to Backpack 4.1 (the latest version).

Laravel Nova: Replace home route and run as default application

I'm playing around with Laravel Nova and considering using it in my application. I was wondering if there is a way to make Nova the default application that loads when I hit the URL i.e. instead of navigating to myapplication.test/nova, I want the nova dashboard to load when I hit myapplication.test. How do I set Laravel home route as the 'nova' dashboard?
Update 1: I came across this https://github.com/laravel/nova-issues/issues/174 but, doesn't seem to work.
Update Nova Path in config/nova.php as 'path' => '/'
If you use Nova with a version under 4 can visit this issue Link
If use Nova version 4 all you need to do in (NovaServiceProvider)
override boot function add this line
public function boot()
{
parent::boot();
Nova::$initialPath = '/';
}
You have to remove the code bellow from routes/web.php
Route::get('/', function () {
return view('welcome');
});
And update Nova Path in config/nova.php to 'path' => '/'

Laravel 4.2 form action not working

I'm new to Laravel and am building a simple web application. I'll show what code I'm using next and then I'll explain my problem.
Here's how my form starts in the view login.blade.php:
<?php
//build the form
echo Form::open(array('action' => 'AuthenticationController#authenticateUser'));
And here's what the route for the home page:
Route::get('/', function() {
return View::make('login', array('page_title' => 'Log in to MANGER'));
});
Finally, here's the authentication controller (for now it's a simple redirect to simulate login):
class AuthenticationController extends BaseController {
public function authenticateUser()
{
//retrive from database
return View::make('hr', array('page_title' => 'MANGER Login'));
}
}
My problem is, I'm getting an error on login.blade.php. saying: Route [AuthenticationController#authenticateUser] not defined. (View: /opt/lampp/htdocs/manger/app/views/login.blade.php)
How is the error about a route when I've defined a controller instead? And also, how can this be fixed? Please excuse any noob errors and thanks a lot in advance! :-)
You still need to define your route like this:
Route::post('authenticate', ['uses' => 'AuthenticationController#authenticateUser']);
Otherwise it won't know what method to use, or the url to create.

Dynamic Slugs in multilingue website Laravel 4

I have a multilingue website created using Laravel 4, and I have lot of pages such as : "policy, "terms", "how it works" in database, so to access thoses pages I use this route:
// Group by locale
Route::group(
array( 'prefix' => $locale ), function () {
Route::get('{slug}', array('uses' => 'PageController#show','as' => 'pages.show');
// Website routes
});
And then I search for the given slug and the current locale.
My is problem is that I can't add for example a page link in the footer because the slug is dynamic. so is there any solution to resolve that.
It's make a sense ?
Thanks
You are already catching the slug in
Route::get('{slug}', array('uses' => 'PageController#show','as' => 'pages.show');
part. all you need is to inject this slug into controller like this:
class PageController extends BaseController {
public function show($slug)
{
return 'showing slug ' . $slug;
}
}
and whatever value the route receive for {slug} part in route laravel will automatically inject that value into the controller.

Resources