/**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Request $request, $id)
 {
     $attachment = \App\Attachment::findOrFail($id);
     $path = attachment_path($attachment->name);
     if (\File::exists($path)) {
         \File::delete($path);
     }
     $attachment->delete();
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     flash()->success(trans('forum.deleted'));
     return back();
 }
Пример #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  * @throws \Exception
  */
 public function destroy(Request $request, $id)
 {
     $article = Article::with('attachments', 'comments')->findOrFail($id);
     foreach ($article->attachments as $attachment) {
         \File::delete(attachment_path($attachment->name));
     }
     $article->attachments()->delete();
     $article->comments->each(function ($comment) {
         app(\App\Http\Controllers\CommentsController::class)->recursiveDestroy($comment);
     });
     $article->delete();
     event(new ModelChanged('articles'));
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     flash()->success(trans('forum.deleted'));
     return redirect(route('articles.index'));
 }
Пример #3
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /*
      * Prepare seeding
      */
     $faker = Faker::create();
     if (config('database.default') != 'sqlite') {
         DB::statement('SET FOREIGN_KEY_CHECKS=0');
     }
     Model::unguard();
     /*
      * Seeding users table
      */
     App\User::truncate();
     factory(App\User::class)->create(['name' => 'John Doe', 'email' => '*****@*****.**', 'password' => bcrypt('password')]);
     factory(App\User::class, 9)->create();
     $this->command->info('users table seeded');
     /**
      * Seeding roles table
      */
     Bican\Roles\Models\Role::truncate();
     DB::table('role_user')->truncate();
     $adminRole = Bican\Roles\Models\Role::create(['name' => 'Admin', 'slug' => 'admin']);
     $memberRole = Bican\Roles\Models\Role::create(['name' => 'Member', 'slug' => 'member']);
     App\User::where('email', '!=', '*****@*****.**')->get()->map(function ($user) use($memberRole) {
         $user->attachRole($memberRole);
     });
     App\User::whereEmail('*****@*****.**')->get()->map(function ($user) use($adminRole) {
         $user->attachRole($adminRole);
     });
     $this->command->info('roles table seeded');
     /*
      * Seeding articles table
      */
     App\Article::truncate();
     $users = App\User::all();
     $users->each(function ($user) use($faker) {
         $user->articles()->save(factory(App\Article::class)->make());
         $user->articles()->save(factory(App\Article::class)->make());
     });
     $this->command->info('articles table seeded');
     /**
      * Seeding comments table
      */
     App\Comment::truncate();
     $articles = App\Article::all();
     $articles->each(function ($article) use($faker, $users) {
         $article->comments()->save(factory(App\Comment::class)->make(['author_id' => $faker->randomElement($users->lists('id')->toArray())]));
     });
     $this->command->info('comments table seeded');
     /*
      * Seeding tags table
      */
     App\Tag::truncate();
     DB::table('article_tag')->truncate();
     $rawTags = ['General', 'Laravel', 'Lumen', 'Eloquent', 'Servers', 'Tips', 'Lesson Feedback'];
     foreach ($rawTags as $tag) {
         App\Tag::create(['name' => $tag, 'slug' => str_slug($tag)]);
     }
     $tags = App\Tag::all();
     foreach ($articles as $article) {
         $article->tags()->attach($faker->randomElements($tags->lists('id')->toArray(), $faker->randomElement([1, 2, 3])));
     }
     $this->command->info('tags table seeded');
     /*
      * Seeding attachments table
      */
     App\Attachment::truncate();
     if (!File::isDirectory(attachment_path())) {
         File::deleteDirectory(attachment_path(), true);
     }
     $articles->each(function ($article) use($faker) {
         $article->attachments()->save(factory(App\Attachment::class)->make());
     });
     $files = App\Attachment::lists('name');
     if (!File::isDirectory(attachment_path())) {
         File::makeDirectory(attachment_path(), 777, true);
     }
     foreach ($files as $file) {
         File::put(attachment_path($file), '');
     }
     $this->command->info('attachments table seeded');
     /**
      * Close seeding
      */
     Model::reguard();
     if (config('database.default') != 'sqlite') {
         DB::statement('SET FOREIGN_KEY_CHECKS=1');
     }
 }
Пример #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param \Illuminate\Http\Request $request
  * @param  int                     $id
  * @return \Illuminate\Http\Response
  * @throws \Exception
  */
 public function destroy(Request $request, $id)
 {
     $article = Article::with('attachments', 'comments')->findOrFail($id);
     foreach ($article->attachments as $attachment) {
         \File::delete(attachment_path($attachment->name));
     }
     $article->attachments()->delete();
     $article->comments->each(function ($comment) use($request) {
         app(\App\Http\Controllers\CommentsController::class)->destroy($request, $comment->id);
     });
     $article->delete();
     event(new ModelChanged('articles'));
     if ($request->ajax()) {
         return response()->json('', 204);
     }
     return $this->respondDeleted($article);
 }
Пример #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $article = Article::with('attachments', 'comments')->findOrFail($id);
     foreach ($article->attachments as $attachment) {
         \File::delete(attachment_path($attachment->name));
     }
     $article->attachments()->delete();
     $article->comments->each(function ($comment) {
         app(\App\Http\Controllers\CommentsController::class)->recursiveDestroy($comment);
     });
     $article->delete();
     flash()->success(trans('forum.deleted'));
     return redirect(route('articles.index'));
 }