Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
batenko1 committed Dec 19, 2024
0 parents commit 2747792
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Posts
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "batenko1/posts",
"description": "description",
"minimum-stability": "stable",
"license": "MIT",
"authors": [
{
"name": "batenko1",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2"
},
"extra": {
"laravel": {
"providers": [
"Batenko1\\Posts\\Providers\\PostServiceProdiver"
]
}
},
"autoload": {
"psr-4": {
"Batenko1\\Posts\\": "src"
}
}
}

44 changes: 44 additions & 0 deletions src/Console/Commands/PostCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Batenko1\Posts\Console\Commands;

use Illuminate\Console\Command;

class PostCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'posts:install';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';


public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*/
public function handle()
{
$ask = $this->ask('Начать установку? (да/нет)');

if (strtolower($ask) === 'да') {
$this->info('Установка началась...');
// Ваш код для выполнения установки
} else {
$this->warn('Установка отменена.');
}

}
}
8 changes: 8 additions & 0 deletions src/Controllers/Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Batenko1\Posts\Controllers;

abstract class Controller
{
//
}
15 changes: 15 additions & 0 deletions src/Controllers/PostController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Batenko1\Posts\Controllers;

use Batenko1\Posts\Models\Post;

class PostController extends Controller
{
public function index() {

$posts = Post::query()->get();

return view('posts::index', compact('posts'));
}
}
15 changes: 15 additions & 0 deletions src/Models/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Batenko1\Posts\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
use HasFactory;

protected $fillable = [
'title'
];
}
40 changes: 40 additions & 0 deletions src/Providers/PostServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Batenko1\Posts\Providers;

use Batenko1\Posts\Console\Commands\PostCommand;
use Illuminate\Support\ServiceProvider;

class PostServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
}

/**
* Bootstrap services.
*/
public function boot(): void
{

$this->loadRoutesFrom(__DIR__.'/../routes/web.php');
$this->loadViewsFrom(__DIR__.'/../resources/views', 'posts');

$this->loadMigrationsFrom(__DIR__.'/../database/migrations');


$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/posts'),
]);

if($this->app->runningInConsole()) {
$this->commands([
PostCommand::class
]);
}

}
}
28 changes: 28 additions & 0 deletions src/database/migrations/2024_12_19_072507_create_posts_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('posts');
}
};
17 changes: 17 additions & 0 deletions src/resources/views/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
@foreach($posts as $post)

{{ $post->id }}.{{ $post->title }} <br>

@endforeach
</body>
</html>
6 changes: 6 additions & 0 deletions src/routes/web.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use Batenko1\Posts\Controllers\PostController;
use Illuminate\Support\Facades\Route;

Route::get('/posts', [PostController::class, 'index']);

0 comments on commit 2747792

Please sign in to comment.