Laravel 4.2 - ReflectionException (-1) - laravel

I am getting following error:
ReflectionException (-1)
Class PhotosController does not exist
This is my route:
Route::resource('photos', ' PhotosController');
When I change to Route::get('photos', 'PhotosController#index'); it is working fine, but using resource it is falling? What is going on?
PhotosController:
<?php
class PhotosController extends \BaseController {
/**
* Display a listing of the resource.
* GET /photos
*
* #return Response
*/
public function index()
{
return Photo::all();
}
/**
* Show the form for creating a new resource.
* GET /photos/create
*
* #return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
* POST /photos
*
* #return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
* GET /photos/{id}
*
* #param int $id
* #return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
* GET /photos/{id}/edit
*
* #param int $id
* #return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
* PUT /photos/{id}
*
* #param int $id
* #return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
* DELETE /photos/{id}
*
* #param int $id
* #return Response
*/
public function destroy($id)
{
//
}
}

If composer dump-autoload doesn't fix it, then it is probably a typo in the class name or routes file, or incorrectly using subdirectories/namespaces on your controllers.

Related

When I submit my data to the text field it is not submitting

This is my Postcontroller code
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PostsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index($id)
{
return "It's working".$id;
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
return view('posts.create');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
return $request->all();
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
return "Show Controller ".$id;
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function contact(){
$people=['Snehal','Swarna','Rhitu','Mashuk','Sajid'];
return view('contact',compact('people'));
}
public function show_post($id,$name,$password){
return view('post',compact('id','name','password'));
}
}
myroute https://i.stack.imgur.com/qLr0b.jpg
My Create view https://i.stack.imgur.com/DfIft.jpg
For your form action, it's suggested to use route() function, like below:
<form method="POST" action="{{ route('posts.store') }}">
You are using resource for /posts. You should rewrite the action form to Ahmad Karimi's answer.
Additionally, you can use dd($request->all()); to see if your form field is submitting to the controller.

Getting an error saying my resource route is not defined

Error: Route [tasks] not defined.
I created a resource route for my TasksController. I feel like I have done everything I needed to do, but still getting this error. It even shows up correctly when I try get a route list through the terminal.
I tried removing the slash, changing the controller name, changing the route name, but to no avail. I cant think of what else to try. The code was copied from another route and controller that I was using to manage projects.
Lastly, I also double checked the view path everything checks out.
Route::resource('/tasks', 'TasksController');
Also here is the code for my controller
<?php
namespace App\Http\Controllers;
use App\Tasks;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class TasksController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$tasks = Tasks::all();
return view('tasks/tasks', compact('tasks'));
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}

Laravel - empty result by trying to show a specific thread

My database is filled with data and showing all data works. But if I try to show a specific thread only, I get an empty result and I can't figure out why.
web.php
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/threads', 'ThreadsController#index');
Route::get('/threads/{threads}', 'ThreadsController#show');
ThreadsController#index works, but ThreadsController#show doesn't work.
ThreadsController.php
<?php
namespace App\Http\Controllers;
use App\Thread;
use Illuminate\Http\Request;
class ThreadsController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$threads = Thread::latest()->get();
return view('threads.index', compact('threads'));
//return $threads;
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param \App\Thread $thread
* #return \Illuminate\Http\Response
*/
public function show(Thread $thread)
{
//return view('threads.show', compact('thread'));
return $thread;
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Thread $thread
* #return \Illuminate\Http\Response
*/
public function edit(Thread $thread)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Thread $thread
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Thread $thread)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param \App\Thread $thread
* #return \Illuminate\Http\Response
*/
public function destroy(Thread $thread)
{
//
}
}
This is an example from laracast tutorial: link
Why this example doesn't work? I can't find any typo in my code.
My version:
php artisan --version
Laravel Framework 5.4.32
Rename your show route to the following:
Route::get('/threads/{thread}', 'ThreadsController#show');
You are loading a Thread object, and not a Threads object.

how i can make a Resource Controllers

when I want create a Resource Controllers by this command : " php artisan make:controller sectionController3 "
I get a Basic Controllers
I don't add --plain
but he gives me Basic Controllers
sorry ^^
When you create a new controller from the command line laravel automatically insert a new resource controller like this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class sectionController3 extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
After this you can create a new route for this controller:
resource('section-controller-3', 'sectionController3');
and this would handle all the RESTful actions about your sectionController3
Have a look to Laravel Docs HTTP Controller to get familiar with how Controllers and Routes work in Laravel.
Hope this helps!

Having trouble understanding links in laravel 4

I have a problem with link_to_action in laravel 4
In laravel 3 i would show a link like
{{ HTML::link_to_action('user/create', 'Create User') }}
But since I've switched to laravel 4 I'm creating my controllers like this UserController but when I try to use the HTML
{{ HTML::linkAction('user/create', 'Create User') }}
It gives me and error that action doesn't exist even though there's a method named create.
Any help would be greatly appreciated.
And here's my controller
<?php
class UserController extends \BaseController {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* #return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
*
* #param int $id
* #return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param int $id
* #return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return Response
*/
public function destroy($id)
{
//
}
}
// L3
{{ HTML::link_to_action('user#create', 'Create User') }}
// L4
{{ HTML::linkAction('UserController#create', 'Create User') }}
edit:
// I think you missed that entry in your routes.php
Route::resource('user', 'UserController');

Resources