0

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

4
  • Why don't you just return view('pages.Register') instead of View::make()? Commented Mar 4, 2018 at 4:13
  • use return redirect('/register'); Commented Mar 4, 2018 at 4:30
  • error show like Whoops, looks like something went wrong. Commented Mar 4, 2018 at 4:36
  • please help to solve Commented Mar 4, 2018 at 4:37

4 Answers 4

1

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');
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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')

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.