# Getting Started with Kotchasan Framework ## Creating a New Project ### 1. Create Project ```bash # Create new project composer create-project kotchasan/framework my-app # Navigate to project directory cd my-app ``` ### 2. Environment Setup ```bash # Copy environment file cp .env.example .env # Generate application key php artisan key:generate ``` ### 3. Database Setup ```bash # Run migrations php artisan migrate # Seed initial data php artisan db:seed ``` ## Project Structure ``` my-app/ ├── app/ │ ├── Controllers/ # Controllers │ ├── Models/ # Models │ ├── Middleware/ # Middleware │ └── Services/ # Business Logic ├── config/ # Configuration files ├── database/ │ ├── migrations/ # Database migrations │ └── seeders/ # Database seeders ├── public/ # Web root ├── resources/ │ ├── views/ # Blade templates │ └── assets/ # CSS, JS, Images ├── routes/ # Route definitions ├── storage/ # Logs, cache, sessions └── tests/ # Test files ``` ## Creating Controllers ### 1. Create New Controller ```bash php artisan make:controller HomeController ``` ### 2. Write Controller ```php 'Home Page', 'message' => 'Welcome to Kotchasan Framework' ]; return $this->view('home', $data); } public function about() { return $this->view('about', [ 'title' => 'About Us' ]); } } ``` ## Creating Models ### 1. Create New Model ```bash php artisan make:model User ``` ### 2. Write Model ```php 'datetime', 'password' => 'hashed', ]; // Relationships public function posts() { return $this->hasMany(Post::class); } } ``` ## Creating Views ### 1. Create View File ```html <?= $title ?>

Features

  • High Performance
  • Security
  • Easy to Use

Usage

Start building your application right away

``` ### 2. Layout Template ```html <?= $title ?? 'Kotchasan Framework' ?>
``` ## Routing Configuration ### 1. Web Routes ```php group(function () { Route::get('/posts', [PostController::class, 'index']); Route::get('/posts/{id}', [PostController::class, 'show']); Route::post('/posts', [PostController::class, 'store']); Route::put('/posts/{id}', [PostController::class, 'update']); Route::delete('/posts/{id}', [PostController::class, 'destroy']); }); ``` ## Working with Database ### 1. Migration ```bash # Create migration php artisan make:migration create_posts_table ``` ```php id(); $table->string('title'); $table->text('content'); $table->unsignedBigInteger('user_id'); $table->timestamps(); $table->foreign('user_id')->references('id')->on('users'); }); } public function down() { Schema::dropIfExists('posts'); } }; ``` ### 2. Seeder ```bash # Create seeder php artisan make:seeder PostSeeder ``` ```php 'First Post', 'content' => 'Content of the first post', 'user_id' => $user->id ]); } } ``` ## Using Forms and Validation ### 1. Create Form ```html
``` ### 2. Validation in Controller ```php validate([ 'title' => 'required|string|max:255', 'content' => 'required|string' ]); // Create post $post = Post::create([ 'title' => $request->title, 'content' => $request->content, 'user_id' => auth()->id() ]); return redirect('/posts/' . $post->id); } } ``` ## Using Middleware ### 1. Create Middleware ```bash php artisan make:middleware AuthMiddleware ``` ```php check()) { return redirect('/login'); } return $next($request); } } ``` ### 2. Register Middleware ```php \App\Middleware\AuthMiddleware::class, 'guest' => \App\Middleware\GuestMiddleware::class, ]; ``` ### 3. Use Middleware in Routes ```php group(function () { Route::get('/dashboard', [DashboardController::class, 'index']); Route::get('/profile', [ProfileController::class, 'index']); }); ``` ## Using Sessions and Cookies ### 1. Session ```php $user->id]); session(['cart' => $cartItems]); // Read data from session $userId = session('user_id'); $cart = session('cart', []); // Remove data from session session()->forget('cart'); ``` ### 2. Cookie ```php put('user_posts', $posts, 3600); // Remove cache by tags Cache::tags(['posts'])->flush(); ``` ## Using Queue ### 1. Create Job ```bash php artisan make:job SendEmailJob ``` ```php email = $email; $this->subject = $subject; $this->message = $message; } public function handle() { // Send email mail($this->email, $this->subject, $this->message); } } ``` ### 2. Dispatch Job ```php delay(now()->addMinutes(5)); ``` ## Testing ### 1. Unit Test ```php 'John Doe', 'email' => 'john@example.com' ]); $this->assertEquals('John Doe', $user->name); $this->assertEquals('john@example.com', $user->email); } } ``` ### 2. Feature Test ```php create(); $response = $this->actingAs($user) ->post('/posts', [ 'title' => 'Test Post', 'content' => 'Test Content' ]); $response->assertStatus(302); $this->assertDatabaseHas('posts', [ 'title' => 'Test Post' ]); } } ``` ## Deployment ### 1. Production Setup ```bash # Environment setup cp .env.example .env # Edit .env for production # Install dependencies composer install --no-dev --optimize-autoloader # Generate key php artisan key:generate # Run migrations php artisan migrate --force # Cache configuration php artisan config:cache php artisan route:cache php artisan view:cache ``` ### 2. Web Server Configuration ```nginx server { listen 80; server_name your-domain.com; root /path/to/kotchasan/public; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; fastcgi_index index.php; include fastcgi_params; } } ``` --- **Note**: This is a getting started guide. For more information, please refer to the [API Reference](api-reference.md)