Reputation: 1
Please Help To Solve This Problem
My Controller
<?php namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use View;
use DB;
class MyCon extends Controller {
/*
|--------------------------------------------------------------------------
| Welcome Controller
|--------------------------------------------------------------------------
|
| This controller renders the "marketing page" for the application and
| is configured to only allow guests. Like most of the other sample
| controllers, you are free to modify or remove it as you desire.
|
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Show the application welcome screen to the user.
*
* @return Response
*/
public function register()
{
//return \View::make('pages.Register');
return view('pages.Register');
}
public function RegisterAction(Request $req)
{
$name = $req->input('name');
$email = $req->input('email');
$gender = $req->input('gender');
$password = $req->input('password');
$data = array("uname" => $name, "uemail" => $email, "ugender" => $gender, "upassword" => $password);
DB::table('user')->insert($data);
//return \View::make('pages.Register');
}
}
My Register Function work fine But When I am Submit Form ON RegisterAction function then show error like 'PHP Fatal error: Class 'App\Http\Controllers\View' not found'
My Router Code
Route::post('RegisterAction', 'MyCon@RegisterAction');
Please Help To Solve This Problem. Thank In Advance
Upvotes: 0
Views: 1710
Reputation: 309
I suggest you redirect to a named route from route web file, try return redirect()->route('route-name');
and if you intend to use view try return view('view-name')
.
Using View::class
means you are calling the view model which is not available except you have a view class created.
Upvotes: 0
Reputation: 895
Activate your APP DEBUGGER first so you can see your code issue by doing APP_DEBUG=true
in your .env file.
including the View class in your controller won't give you an issue and restrict you to use the class or since you're using Laravel 5 you can use the function view()
by simply calling view('SOMEVIEWHERE')
Upvotes: 0
Reputation: 6773
as you have changed the name like this
use Illuminate\Routing\Controller as BaseController;
change
class MyCon extends Controller {
to
class MyCon extends BaseController {
and you can use view helper function instead of importing View class yourself like this.
public function register()
{
return view('pages.Register');
}
Upvotes: 1
Reputation: 15951
Laravel Provides a nice helper to for View class.
return view('pages.Register');
Secondly you can also use
use View; //on top
View::make('pages.Register');
Hope this helps
Upvotes: 0