Last active
July 5, 2018 15:03
-
-
Save arif98741/a98529b4d08decc4015aab95b0720722 to your computer and use it in GitHub Desktop.
Laraval User Existance Check
This file contains hidden or 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 Illuminate\Support\Facades\DB; //must need to add during work with database | |
use App\Http\Controllers\Controller; | |
class UserController extends Controller | |
{ | |
public function store(Request $request) | |
{ | |
//validate the data | |
$this->validate($request,array( | |
'title' => 'required|max:255', | |
'slug' => 'required|alpha_dash|min:5|max:255|unique:posts,slug', | |
'body' => 'required', | |
'email' => 'required' | |
)); | |
//store in databaes | |
$post = new Post; //object of post modal | |
$post->title = $request->title; | |
$post->slug = $request->slug; | |
$post->body = $request->body; | |
$post->email = $request->email; | |
$user = DB::table('users')->where('email', $post->email)->first(); //return 1 row | |
if ($user !== null || $user !== "") { | |
//save data | |
$post->save(); | |
//session mesage | |
Session::flash('success','Your data has save successfully'); | |
//redirect with success message | |
return redirect()->route('posts.show',$post->id); | |
} else { | |
//redirect to create page again | |
return redirect()->route('posts.create'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment