Skip to content

Commit 9cbe797

Browse files
author
Sashagm
committed
'init'
0 parents  commit 9cbe797

File tree

12 files changed

+205
-0
lines changed

12 files changed

+205
-0
lines changed

.gitignove

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Учусь делать пакеты для ларавел
2+
3+
#### Установка
4+
5+
- composer require sashagm/posts
6+
- php artisan vendor:publish --provider="Sashagm\Posts\Providers\PostServiceProvider"

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "sashagm/posts",
3+
"description": "description",
4+
"minimum-stability": "stable",
5+
"license": "MIT",
6+
"authors": [{
7+
"name": "sashagm",
8+
"email": "example@example.com"
9+
}
10+
],
11+
"require": {
12+
"php": "^7.3|^8.0"
13+
},
14+
"autoload": {
15+
"psr-4": {
16+
"Sashagm\\Posts\\": "src"
17+
}
18+
},
19+
"extra": {
20+
"laravel": {
21+
"providers": [
22+
"Sashagm\\Posts\\Providers\\PostServiceProvider"
23+
]
24+
}
25+
}
26+
27+
}

src/Console/Commands/PostCommand.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Sashagm\Posts\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
7+
class PostCommand extends Command
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'posts:install';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Command description';
22+
23+
/**
24+
* Execute the console command.
25+
*
26+
* @return int
27+
*/
28+
public function handle()
29+
{
30+
$ask = $this->ask('Начать установку?');
31+
dd($ask);
32+
}
33+
}

src/Http/Controllers/Controller.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Sashagm\Posts\Http\Controllers;
4+
5+
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
6+
use Illuminate\Foundation\Bus\DispatchesJobs;
7+
use Illuminate\Foundation\Validation\ValidatesRequests;
8+
use Illuminate\Routing\Controller as BaseController;
9+
10+
class Controller extends BaseController
11+
{
12+
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
13+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Sashagm\Posts\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Sashagm\Posts\Models\Post;
7+
8+
class PostController extends Controller
9+
{
10+
public function index()
11+
{
12+
//Post::create(['title' => 'test']);
13+
14+
$posts = Post::all();
15+
return view('posts::index',[
16+
'posts' => $posts,
17+
]);
18+
}
19+
}

src/Models/Post.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Sashagm\Posts\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Post extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['title'];
13+
}

src/Providers/PostServiceProvider.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Sashagm\Posts\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
use Sashagm\Posts\Console\Commands\PostCommand;
7+
8+
class PostServiceProvider extends ServiceProvider
9+
{
10+
/**
11+
* Register services.
12+
*
13+
* @return void
14+
*/
15+
public function register()
16+
{
17+
//
18+
}
19+
20+
/**
21+
* Bootstrap services.
22+
*
23+
* @return void
24+
*/
25+
public function boot()
26+
{
27+
$this->loadRoutesFrom(__DIR__.'/../routes/posts.php');
28+
$this->loadViewsFrom(__DIR__.'/../resources/views', 'posts');
29+
$this->loadMigrationsFrom(__DIR__.'/../database/migrations');
30+
31+
$this->publishes([
32+
__DIR__.'/../resources/views' => resource_path('views/vendor/posts'),
33+
]);
34+
35+
$this->publishes([
36+
__DIR__.'/../config/posts.php' => config_path('posts.php'),
37+
]);
38+
39+
if ($this->app->runningInConsole()) {
40+
$this->commands([
41+
PostCommand::class,
42+
]);
43+
}
44+
}
45+
}

src/config/posts.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
return [
4+
"variable" => "variable_test",
5+
];
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('posts', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('title');
19+
$table->timestamps();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::dropIfExists('posts');
31+
}
32+
};

src/resources/views/index.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@foreach($posts as $post)
2+
3+
{{ $post->title }}
4+
5+
@endforeach

src/routes/posts.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
6+
Route::get('/posts', [\Sashagm\Posts\Http\Controllers\PostController::class, 'index']);

0 commit comments

Comments
 (0)