Created
July 20, 2020 09:53
-
-
Save saeedhajinasiri/3816f253762c9d356fb1e3a537d1249f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Controllers; | |
use App\Contact; | |
use Response; | |
use App\Http\Requests; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
class ContactController extends Controller | |
{ | |
public function index() | |
{ | |
$data = Contact::orderBy('id','desc')->paginate(10)->setPath('contacts'); | |
return view('admin.contacts.index',compact(['data'])); | |
} | |
public function create() | |
{ | |
return view('admin.contacts.create'); | |
} | |
public function store(Request $request) | |
{ | |
$request->validate([ | |
'name' => 'required', | |
'email' => 'required|email', | |
'phone' => 'required' | |
]); | |
Contact::create($request->all()); | |
return redirect()->back()->with('success','Create Successfully'); | |
} | |
public function show($id) | |
{ | |
$data = Contact::find($id); | |
return view('admin.contacts.show',compact(['data'])); | |
} | |
public function edit($id) | |
{ | |
$data = Contact::find($id); | |
return view('admin.contacts.edit',compact(['data'])); | |
} | |
public function update(Request $request, $id) | |
{ | |
$request->validate([ | |
'name' => 'required', | |
'email' => 'required|email', | |
'phone' => 'required' | |
]); | |
Contact::where('id',$id)->update($request->all()); | |
return redirect()->back()->with('success','Update Successfully'); | |
} | |
public function destroy($id) | |
{ | |
Contact::where('id',$id)->delete(); | |
return redirect()->back()->with('success','Delete Successfully'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment