first(); $user = \App\Models\User::find(1); foreach($videos as $video) { if(\App\Models\Video::whereFile(basename($video))->count() > 0) continue; $v = new \App\Models\Video(); $v->user()->associate($user); $v->category()->associate($category); $v->hash = sha1_file($video); $v->file = basename($video); $v->save(); } } }