/** * @param Project $project * @param Tag $tags * @return \Illuminate\Contracts\View\View * @throws \Exception */ public function index(Project $project, Tag $tags) { $projects = $project->with($this->relations())->orderBy('date', 'desc')->get(); $options = ['columns' => $this->theme->setting('portfolioColumns'), 'grid' => $this->theme->setting('portfolioGrid'), 'spaced' => $this->theme->setting('portfolioSpaced')]; $tags = $projects->getUniqueTags(); return $this->theme->render('portfolio.index', ['projects' => $projects, 'options' => $options, 'tags' => $tags]); }
/** * @param Project $portfolio * @param Request $request */ public function store(Project $portfolio, Request $request) { $status = $request->get('status'); if ($status) { $portfolio->collaborators()->attach($request->get('member')); } else { $portfolio->collaborators()->detach($request->get('member')); } }
/** * @param Project $project */ public function deleting(Project $project) { $project->collaborators()->sync([]); foreach ($project->tags as $tag) { $this->dispatch(new UntagSomething($project, $tag)); } $project->translations()->delete(); foreach ($project->images as $image) { $image->delete(); } }
public function run($creating = 15) { foreach ([1, 2] as $accountid) { $account = Account::find($accountid); $clients = Client::all(); $users = User::all(); $users = $users->lists('id')->toArray(); //flip so we can use array_rand $tags = array_flip(Tag::lists('id')->toArray()); for ($i = 0; $i < $creating; $i++) { $project = Modules\Portfolio\Project::create(['account_id' => $account->id, 'date' => $this->nl->dateTimeBetween('-3 months', 'now'), 'website' => $this->nl->url, 'nl' => ['published' => rand(0, 1), 'title' => $this->nl->sentence(2), 'content' => $this->nl->text(1300), 'created_at' => $this->nl->dateTimeBetween('-3 months', 'now'), 'updated_at' => $this->nl->dateTimeBetween('-2 months', 'now')], 'fr' => ['published' => rand(0, 1), 'title' => $this->fr->sentence(2), 'content' => $this->fr->text(1300), 'created_at' => $this->fr->dateTimeBetween('-3 months', 'now'), 'updated_at' => $this->fr->dateTimeBetween('-2 months', 'now')], 'en' => ['published' => rand(0, 1), 'title' => $this->en->sentence(2), 'content' => $this->en->text(1300), 'created_at' => $this->en->dateTimeBetween('-3 months', 'now'), 'updated_at' => $this->en->dateTimeBetween('-2 months', 'now')], 'de' => ['published' => rand(0, 1), 'title' => $this->de->sentence(2), 'content' => $this->de->text(1300), 'created_at' => $this->de->dateTimeBetween('-3 months', 'now'), 'updated_at' => $this->de->dateTimeBetween('-2 months', 'now')]]); $this->addImages($project); //foreach project we randomly add 1 to 3 collaborators $amount = rand(1, 3); $possibleUsers = $users; for ($j = 0; $j < $amount; $j++) { shuffle($possibleUsers); $add = array_shift($possibleUsers); $project->collaborators()->attach($add); } $project->tags()->sync(array_rand($tags, 2)); $project->client()->associate($clients->random()); $project->save(); } } }
/** * @param Request $request * @param Project $project */ public function batchUnpublish(Request $request, Project $project) { $ids = $request->get('projects', []); if (is_array($ids) && count($ids)) { $projects = $project->whereIn('portfolio_projects.id', $ids)->get(); foreach ($projects as $project) { $translation = $project->translate($request->get('locale')); if ($translation) { $translation->published = false; } $translation->save(); } } }
/** * * $newsletter */ protected function getMaps() { $posts = new Collection(); $projects = new Collection(); $this->each(function ($widget) use($projects, $posts) { if ($widget->resource) { if ($widget->resource_type == Post::class) { $posts->push($widget->resource_id); } if ($widget->resource_type == Project::class) { $projects->push($widget->resource_id); } } if ($widget->other_resource) { if ($widget->other_resource_type == Post::class) { $posts->push($widget->other_resource_id); } if ($widget->other_resource_type == Project::class) { $projects->push($widget->other_resource_id); } } }); $posts = Post::whereIn('posts.id', $posts->all())->with(['translations', 'images', 'images.sizes'])->get(); $projects = Project::whereIn('portfolio_projects.id', $projects->all())->with(['translations', 'images', 'images.sizes'])->get(); return [$posts, $projects]; }
protected function listeners() { Project::observe(ProjectObserver::class); }
/** * @return bool|Project */ public function handle() { $this->project->fill($this->input); return $this->project->save() ? $this->project : false; }