I'm working in a laravel application and trying to implement delete() method in a controller but it doesn't work.
This is the Error:
BadMethodCallException in Controller.php line 283: Method [delete] does not exist.
Here is my view (buss.blade.php)
<a href="{!! URL::to('delete_bus', array($u->id)) !!}">
<span class="glyphicon glyphicon-minus"></span>
</a>
Here is my Route:
Route::get('delete_bus/{id}', array('uses' => 'adminController#delete'));
and it exists in app/resources/admin/buss.blade.php
And Here is my Controller Method
public function delete_bus($id) {
$reg = Business::find($id);
$reg->delete();
return Redirect::to('buss')->with('del', 'Sucessfully Deleted!');
}
You named your controller method delete_bus, but your trying to route to delete method. Change your route to this:
Route::get('delete_bus/{id}', array('uses' => 'adminController#delete_bus'));
And your controller should be called with capital letters, so this could be potential bug as well.
Related
I'm getting this error even though the route is defined
Route [blood-camp] not defined. (View: C:\wamp64\www\blood-donation\resources\views\layouts\app.blade.php)
web.php file
`Route::get('/', [App\Http\Controllers\HomeController::class, 'index'])->name('home.root');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/user', [App\Http\Controllers\UserController::class, 'index'])->name('user');
Route::resource('blood-camp', BloodCampController::class);
Route::resource('donor', DonorController::class);
Route::resource('camp-schedule', CampScheduleController::class);`
app.blade.php
<li class="nav-item dropdown">
<a class="nav-link" href="{{ route('blood-camp') }}" role="button" >
{{ __('Camps') }}
</a>
</li>
controller class
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class BloodCampController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
return view('blood_camp.index', ['camps' => DB::table('blood_camps')->orderBy('name', 'ASC')->paginate(10)]);
}
//all the other resources are there...
}
route:list
There is no duplicate route
I have tried all the suggested ways including changing path names, cache clearing, private window, restarting server, but I'm still getting this error and no way to go further developments.
It first occurred when I adding new route called camp, I changed the name to blood-camp but no luck, now it throw exceptions for the other routes as well. Can someone please explain me what I'm doing wrong?
As the result of your route:list shows, you dont have a route with the alias blood-camp.
What you have as alias is blood-camp.index, blood-camp.store....
To generate the link of the ressources listing use:
By path/url
{{ url('blood-camp') }}
Or by alias
{{ route('blood-camp.index') }}
AdminLTE Laravel template screenshoot:
how can i direct the link into my page in folder lapor/one.blade.php and lapor/two.blade.php?
<li class="treeview">
<a><i class='fa fa-file'></i> <span>Laporan</span> <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li>One</li>
<li>Two</li>
</ul>
</li>
Make a route like below
Route::get('one', function () {
return view('lapor.one');
});
Route::get('two', function () {
return view('lapor.two');
});
And link it like below
<li>One</li>
I would group your adminLTE routes:
Route::group(['prefix' => 'admin', 'as' => 'admin.'], function()
{
Route::get('/', ['as' => 'dashboard', 'uses' => 'AdminController#index']);
Route::get('users', ['as' => 'user', 'uses' => 'AdminController#users']);
});
We prefixed those routes with /admin/ or whatever you want to call it. Then we prefixed their name with admin (using 'as').
Now get a specific route url:
{{ route('admin.dashboard') }}
Why do it like this?
Naming your routes is very important because if the route url changes and your app has hardcored urls (like url('/admin/dashboard') your entire application will break. With named routes this wont happen.
You can do it in three step:
make a function in your controller.like below
publice function functionName(){
return view('yourpagename(one)');
}
go to routes folder open web.php and connect with your controller function in routes. like
Route::get('page-name', 'controllerName#functionName');
add this url to your view page link tag
{{URL::to('page-name')}}
Hope it will works fine.
Before going to redirect the page two steps you need to do :
Step 1:
Define Methods in controller(named as SampleController) for example:
//Controller Name:SampleController
// Method Names defined in controller :lapor1,lapor2
//Method 1
public function lapor1(){
return view('lapor.one');
}
//Method 2
public function lapor2(){
return view('lapor.two');
}
Step :2
Define Routes for the pages like below:
Route::get('lapor1', ['as' => 'laporone','uses'=>'SampleController#lapor1']);
Route::get('lapor2', ['as' => 'laportwo','uses'=>'SampleController#lapor2']);
Step 3:
Link up to view pages now:
<li>One</li>
<li>Two</li>
i have route like this :
Route::controller('/users', 'AdminUsersController', array(
"revokeUser" => "admin.user.revoke_user",
));
and this is my controller
public function revokeUser($nationalCode)
{
dd("I'm in");
}
but when im going to use route i have exception route not defined
<a class="btn btn-warning btn-sm" href="{{ URL::route('admin.user.revoke_user',array($user->national_code)) }}">
Click here
</a>
exception :
Route [admin.user.revoke_user] not defined. (View:
/var/www/pedram.dev/blog/app/views/admin/users/index.blade.php)
You can use this in routes.php
Route::match(['get', 'post'], '/users/{nationalCode}', ['as' => 'admin.user.revoke_user', 'uses' => 'AdminUsersController#revokeUser']);
EDIT you are getting error because your function takes argument and in your route definition you haven't defined argument. So you need :
Route::controller('/users/{nationalCode}', 'AdminUsersController', array(
"revokeUser" => "admin.user.revoke_user",
));
Here is my routes.php:
Route::group(['prefix' => 'mine'], function () {
Route::get('/first', ['as' => 'mine.first', 'uses' => 'MyApp\Controllers\MyController#first']);
});
Here is my HTML/Twig file:
{{ form_open({'action': 'mine.first'}) }}
{{ form_submit('Start') }}
{{ form_close }}
And here is my controller:
class MyController extends BaseController {
public function first()
{
\View::make('stuff.mine.first'); //in folder app/views/stuff/mine
}
}
The error is "An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "MyController#first" as such route does not exist.") in "stuff.show" at line 130."
All the answers on this topic that I've seen are to name the route, but I've already done that.
Also, when I go to the URL manually (localhost/mine/first), the screen is blank even though there is HTML in that file.
Any idea what's going on? Thanks.
mine.first is a route name, not an action.
Use:
{{ form_open({'route': 'mine.first'}) }}
As for the view, controller action need to return a Response (the View generates one), so you just need add the proper keyword:
public function first()
{
return \View::make('stuff.mine.first');
}
I am aware that my code is slightly wrong (hence my post!). I am wanting my 'home' view to be displayed when a visitor accesses the '/' part of the website.
Currently, the view works when a user accesses the '/home' part of the website. I am currently pulling my hair out on how to do this!
Route.php:
Route::controller('/', 'HomeController');
Route::controller('users', 'UsersController');
Route::get('events/{id}/{slug}', 'EventsController#show');
Route::controller('events', 'EventsController');
HomeController.php:
<?php
class HomeController extends BaseController {
protected $layout = "layouts.main";
public function getHome(){
$events = myApp\Event::where('date','>=', DB::raw('CURDATE()'))->first();
$this->layout->content = View::make('home', array('events' => $events));
}
}
Home.blade.php:
<div class="col-md-4">
<h2>Next Event</h2>
<h3>{{$events->title}}</h3>
<p>Presented by {{ $events->consultant()->first()->title }} {{ $events->consultant()->first()->surname }}</p>
<b><p>{{ date("j F Y", strtotime($events->date)) }} from {{ date("g:ia", strtotime($events->start_time)) }}</p></b>
<a class="btn btn-success" href="{{ URL::to('events/' . $events->slug) }}">Book your place now.</a>
</div>
I have managed to get the view working with the '/' directory by using this within my routes.php:
Route::get('/', function(){
return View::make('home');
});
However, I am presented with the error:
Undefined variable: events (View:/Users/Sites/gp/app/views/home.blade.php).
It's as if, the HomeController isn't passing the 'events' array into the view, by just changing the route?! Any help/remedy/explanation would be hugely appreciated.
That's how Laravel RESTful controllers works, but you can create a new route for /, before your other routes, pointing to that action:
Route::controller('users', 'UsersController');
Route::get('events/{id}/{slug}', 'EventsController#show');
Route::controller('events', 'EventsController');
Route::get('/', 'HomeController#getHome');
Route::controller('/', 'HomeController');
EDIT
You have to understand that the Laravel Routing System tries to resolve a route as fast as it can, so if it finds a route that fits the current URI, it will use that route and forget about all the others. An example:
Route::get('/{variable}' 'Controller#action');
This is pretty generic route and can be resolved to anything, even
http://your-site.dev/events
So, if you add that route before this one:
Route::get('events/{id}/{slug}', 'EventsController#show');
Your events route will never be hit. That's why your most generic route have to be the last one.