public function run() { $params = Parameter::lists('id'); $tags = Tag::all(); foreach ($tags as $tag) { $tag->params()->attach($randValues = array_intersect_key($params, array_flip(array_rand($params, 2)))); } }
public function run() { $imgs = Image::lists('id'); $tags = Tag::all(); foreach ($tags as $tag) { $tag->images()->attach($randValues = array_intersect_key($imgs, array_flip(array_rand($imgs, 2)))); } }
public function run() { $options = Option::lists('id'); $tags = Tag::all(); foreach ($tags as $tag) { $tag->options()->attach($randValues = array_intersect_key($options, array_flip(array_rand($options, 2)))); } }
public function boot(Router $router) { parent::boot($router); $router->bind('tags', function ($slug) { return Tag::where('slug', $slug)->firstOrFail(); }); $router->bind('options', function ($slug) { return Option::where('slug', $slug)->firstOrFail(); }); $router->bind('parameters', function ($slug) { return Parameter::where('slug', $slug)->firstOrFail(); }); }
private function deleteImages($id) { $files = []; $files = glob(storage_path() . '/tag_images/*-' . $id . '.jpg'); if (count($files) > 0) { foreach ($files as $file) { unlink($file); } } $tag = Tag::find($id); $tag->images()->delete(); }