add status when entering data to database

Posted 9 months ago by wardaddy

I want to create a status when entering data into the database, if the data is successfully created then the status appears successfully created, and if failed appear unsuccessful, I try like this


public function store(Request $request)
        $this->validate(request(), [
            'name' => 'required|string|min:3|max:40',
            'email' => 'required|string|email|max:40|unique:users',
            'username' => 'required|string|min:6|max:20|alpha_dash|unique:users',
            'password' => 'required|string|min:6|max:40',

    $created = User::create([
                    'type_id' => request('user_type'),
                    'name' => request('name'),
                    'email' => request('email'),
                    'username' => request('username'),
                    'password' => bcrypt(request('password')),

    $success = 'Successfully Created';
    $failed = 'Not Successfully Created';

    if ($created) {
        return back()->with('status', $success);
    } else {
        return back()->with('status', $failed);


@if (session('status'))
        $(document).ready(function() {
                html: '{{ session('status') }}',
                displayLength: '10000'

when the data successfully entered into the database, the status appears successfully created as I expected, but if the data is not successfully entered into the database it does not display any status, what should I do?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.