Skip to content

Commit 0ab64f5

Browse files
committed
Первая версия проекта. The first version
0 parents  commit 0ab64f5

File tree

157 files changed

+101202
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+101202
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.env.example

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
APP_NAME=Laravel
2+
APP_ENV=local
3+
APP_KEY=
4+
APP_DEBUG=true
5+
APP_URL=http://localhost
6+
7+
LOG_CHANNEL=stack
8+
9+
DB_CONNECTION=mysql
10+
DB_HOST=127.0.0.1
11+
DB_PORT=3306
12+
DB_DATABASE=homestead
13+
DB_USERNAME=homestead
14+
DB_PASSWORD=secret
15+
16+
BROADCAST_DRIVER=log
17+
CACHE_DRIVER=file
18+
QUEUE_CONNECTION=sync
19+
SESSION_DRIVER=file
20+
SESSION_LIFETIME=120
21+
22+
REDIS_HOST=127.0.0.1
23+
REDIS_PASSWORD=null
24+
REDIS_PORT=6379
25+
26+
MAIL_DRIVER=smtp
27+
MAIL_HOST=smtp.mailtrap.io
28+
MAIL_PORT=2525
29+
MAIL_USERNAME=null
30+
MAIL_PASSWORD=null
31+
MAIL_ENCRYPTION=null
32+
33+
PUSHER_APP_ID=
34+
PUSHER_APP_KEY=
35+
PUSHER_APP_SECRET=
36+
PUSHER_APP_CLUSTER=mt1
37+
38+
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
39+
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

.gitattributes

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored
4+
*.js linguist-vendored
5+
CHANGELOG.md export-ignore

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/node_modules
2+
/public/hot
3+
/public/storage
4+
/storage/*.key
5+
/vendor
6+
/.idea
7+
/.vscode
8+
/nbproject
9+
/.vagrant
10+
Homestead.json
11+
Homestead.yaml
12+
npm-debug.log
13+
yarn-error.log
14+
.env
15+
.phpunit.result.cache

app/Article.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Article extends Model
8+
{
9+
// Mass assigned
10+
protected $guarded = [];
11+
12+
// Mutators
13+
public function setSlugAttribute($value) {
14+
$this->attributes['slug'] = str_slug( mb_substr($this->title, 0, 40) . "-" . \Carbon\Carbon::now()->format('dmyHi'), '-');
15+
}
16+
17+
// Polymorphic relation with categories
18+
public function categories()
19+
{
20+
return $this->morphToMany('App\Category', 'categoryable');
21+
}
22+
23+
public function scopeLastArticles($query, $count)
24+
{
25+
return $query->orderBy('created_at', 'desc')->take($count)->get();
26+
}
27+
}

app/Category.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Category extends Model
8+
{
9+
// Mass assigned
10+
protected $guarded = [];
11+
12+
// Mutators
13+
public function setSlugAttribute($value) {
14+
$this->attributes['slug'] = str_slug( mb_substr($this->title, 0, 40) . "-" . \Carbon\Carbon::now()->format('dmyHi'), '-');
15+
}
16+
17+
// Get children category
18+
public function children() {
19+
return $this->hasMany(self::class, 'parent_id');
20+
}
21+
22+
// Polymorphic relation with articles
23+
public function articles()
24+
{
25+
return $this->morphedByMany('App\Article', 'categoryable');
26+
}
27+
28+
public function scopeLastCategories($query, $count)
29+
{
30+
return $query->orderBy('created_at', 'desc')->take($count)->get();
31+
}
32+
}

app/Console/Kernel.php

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
//
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
31+
/**
32+
* Register the commands for the application.
33+
*
34+
* @return void
35+
*/
36+
protected function commands()
37+
{
38+
$this->load(__DIR__.'/Commands');
39+
40+
require base_path('routes/console.php');
41+
}
42+
}

app/Exceptions/Handler.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
7+
8+
class Handler extends ExceptionHandler
9+
{
10+
/**
11+
* A list of the exception types that are not reported.
12+
*
13+
* @var array
14+
*/
15+
protected $dontReport = [
16+
//
17+
];
18+
19+
/**
20+
* A list of the inputs that are never flashed for validation exceptions.
21+
*
22+
* @var array
23+
*/
24+
protected $dontFlash = [
25+
'password',
26+
'password_confirmation',
27+
];
28+
29+
/**
30+
* Report or log an exception.
31+
*
32+
* @param \Exception $exception
33+
* @return void
34+
*/
35+
public function report(Exception $exception)
36+
{
37+
parent::report($exception);
38+
}
39+
40+
/**
41+
* Render an exception into an HTTP response.
42+
*
43+
* @param \Illuminate\Http\Request $request
44+
* @param \Exception $exception
45+
* @return \Illuminate\Http\Response
46+
*/
47+
public function render($request, Exception $exception)
48+
{
49+
return parent::render($request, $exception);
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Article;
6+
use App\Category;
7+
use Illuminate\Http\Request;
8+
use App\Http\Controllers\Controller;
9+
10+
class ArticleController extends Controller
11+
{
12+
/**
13+
* Display a listing of the resource.
14+
*
15+
* @return \Illuminate\Http\Response
16+
*/
17+
public function index()
18+
{
19+
return view('admin.article.index', [
20+
'articles' => Article::orderBy('created_at', 'desc')->paginate(10)
21+
]);
22+
}
23+
24+
/**
25+
* Show the form for creating a new resource.
26+
*
27+
* @return \Illuminate\Http\Response
28+
*/
29+
public function create()
30+
{
31+
return view('admin.article.create', [
32+
'article' => [],
33+
'categories' => Category::with('children')->where('parent_id', 0)->get(),
34+
'delimiter' => ''
35+
]);
36+
}
37+
38+
/**
39+
* Store a newly created resource in storage.
40+
*
41+
* @param \Illuminate\Http\Request $request
42+
* @return \Illuminate\Http\Response
43+
*/
44+
public function store(Request $request)
45+
{
46+
$article = Article::create($request->except(['categories', 'files']));
47+
48+
// Categories
49+
if($request->input('categories')) :
50+
$article->categories()->attach($request->input('categories'));
51+
endif;
52+
53+
return redirect()->route('admin.article.index');
54+
}
55+
56+
/**
57+
* Display the specified resource.
58+
*
59+
* @param \App\Article $article
60+
* @return \Illuminate\Http\Response
61+
*/
62+
public function show(Article $article)
63+
{
64+
//
65+
}
66+
67+
/**
68+
* Show the form for editing the specified resource.
69+
*
70+
* @param \App\Article $article
71+
* @return \Illuminate\Http\Response
72+
*/
73+
public function edit(Article $article)
74+
{
75+
return view('admin.article.edit', [
76+
'article' => $article,
77+
'categories' => Category::with('children')->where('parent_id', 0)->get(),
78+
'delimiter' => ''
79+
]);
80+
}
81+
82+
/**
83+
* Update the specified resource in storage.
84+
*
85+
* @param \Illuminate\Http\Request $request
86+
* @param \App\Article $article
87+
* @return \Illuminate\Http\Response
88+
*/
89+
public function update(Request $request, Article $article)
90+
{
91+
$article->update($request->except(['slug', 'categories', 'files']));
92+
93+
// Categories
94+
if ($request->has('title')) {
95+
$article->categories()->detach();
96+
if($request->input('categories')) :
97+
$article->categories()->attach($request->input('categories'));
98+
endif;
99+
}
100+
101+
return redirect()->route('admin.article.index');
102+
}
103+
104+
/**
105+
* Remove the specified resource from storage.
106+
*
107+
* @param \App\Article $article
108+
* @return \Illuminate\Http\Response
109+
*/
110+
public function destroy(Article $article)
111+
{
112+
$article->categories()->detach();
113+
$article->delete();
114+
115+
return redirect()->route('admin.article.index');
116+
}
117+
}

0 commit comments

Comments
 (0)