lundi 30 janvier 2017

Laravel 5 check if value exist in database insert another value once

i am new in laravel and i try to insert some values from json array to database, and i want to check if record exits, and if exists want to insert another value. below code works fine for the first time, but when i refresh it changes inserted records again. how i can check the value when inserting first time and when refreshed i dont want to change inserted records. i hope u can help

        $slug = str_slug($post->post_title, '-');

        if (!empty($slug)) {
            if (Post::where('post_slug', '=', $slug)->exists()) {
                $post->post_slug = $post->post_id;
            } else {
                $post->post_slug = $slug;
            }
        } elseif (empty($slug)) {
            $post->post_slug = $post->post_id;
        }
            $post->save();



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kKiB61
via IFTTT

Aucun commentaire:

Enregistrer un commentaire