Skip to content

Commit

Permalink
veritabanı paketini kurduk
Browse files Browse the repository at this point in the history
  • Loading branch information
tayfunerbilen committed May 1, 2021
1 parent e197011 commit 7206265
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 20 deletions.
8 changes: 8 additions & 0 deletions .env.example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

return [
'DB_NAME' => '',
'DB_USER' => '',
'DB_PASSWORD' => '',
'DEVELOPMENT' => true
];
4 changes: 3 additions & 1 deletion .env.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

return [
'DB_HOST' => 'localhost',
'DB_NAME' => 'boilerplate',
'DB_USER' => 'root',
'DB_PASSWORD' => 'root',
'DEVELOPMENT' => true
];
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
.idea
.idea
.env.php
51 changes: 40 additions & 11 deletions app/controllers/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
namespace App\Controllers;

use App\Middlewares\CheckAuth;
use App\Models\Post;
use App\Models\Posts;
use App\Models\User;
use App\Models\Users;
use Core\Controller;
use Illuminate\Database\Capsule\Manager;
use Symfony\Component\HttpFoundation\Request;

class Home extends Controller
Expand All @@ -15,21 +20,45 @@ class Home extends Controller

public function main(Request $request)
{
if ($request->getMethod() === 'POST'){
$this->validator->rule('required', ['username', 'password', 'password_again'])
->rule('equals', 'password', 'password_again');
// if ($request->getMethod() === 'POST'){
// $this->validator->rule('required', ['username', 'password', 'password_again'])
// ->rule('equals', 'password', 'password_again');
// $this->validator->labels([
// 'username' => 'Kullanıcı adı',
// 'password' => 'Parola',
// 'password_again' => 'Parola Tekrarı'
// ]);
// if ($this->validator->validate()){
//// print_r($this->validator->data());
// } else {
//// print_r($this->validator->errors());
// }
// }

if ($request->getMethod() === 'POST') {
$this->validator->rule('required', ['content']);
$this->validator->labels([
'username' => 'Kullanıcı adı',
'password' => 'Parola',
'password_again' => 'Parola Tekrarı'
'content' => 'İçerik'
]);
if ($this->validator->validate()){
// print_r($this->validator->data());
} else {
// print_r($this->validator->errors());
if ($this->validator->validate()) {
$data = $this->validator->data();
$data['user_id'] = 2;
Post::create($data);
}
}
return $this->view('home');

// $posts = Manager::table('posts')
// ->select(['posts.*', 'users.name as user_name'])
// ->join('users', 'users.id', '=', 'user_id')
// ->orderBy('posts.id', 'asc')
// ->get();

// $posts = Posts::all();
// $user = User::find(2);
// $posts = $user->posts;

$posts = Post::all();
return $this->view('home', compact('posts'));
}

public function uyelerSayfasi()
Expand Down
2 changes: 1 addition & 1 deletion app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// helpers

function genv($key, $default = null)
function config($key, $default = null)
{
return \Arrilot\DotEnv\DotEnv::get($key, $default);
}
20 changes: 20 additions & 0 deletions app/models/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Models;

use Core\Model;

class Post extends Model
{

// public $timestamps = false;
protected $fillable = [
'content',
'user_id'
];

public function user()
{
return $this->belongsTo(User::class);
}
}
13 changes: 13 additions & 0 deletions app/models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Models;

use Core\Model;

class User extends Model
{
public function posts()
{
return $this->hasMany(Post::class);
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"jenssegers/blade": "^1.4",
"vlucas/valitron": "^1.4",
"filp/whoops": "^2.12",
"arrilot/dotenv-php": "^2.0"
"arrilot/dotenv-php": "^2.0",
"illuminate/database": "^8.40"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 18 additions & 1 deletion core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Core;

use Buki\Router\Router;
use Illuminate\Database\Capsule\Manager as Capsule;
use Valitron\Validator;
use Arrilot\DotEnv\DotEnv;
use Whoops\Handler\PrettyPageHandler;
Expand All @@ -23,10 +24,26 @@ public function __construct()
$whoops = new Run();
$whoops->pushHandler(new PrettyPageHandler());

if (genv('DEVELOPMENT')) {
if (config('DEVELOPMENT')) {
$whoops->register();
}

$capsule = new Capsule;

$capsule->addConnection([
'driver' => 'mysql',
'host' => config('DB_HOST', 'localhost'),
'database' => config('DB_NAME'),
'username' => config('DB_USER'),
'password' => config('DB_PASSWORD'),
'charset' => config('DB_CHARSET', 'utf8mb4'),
'collation' => config('DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => config('DB_PREFIX'),
]);

$capsule->setAsGlobal();
$capsule->bootEloquent();

$this->router = new Router([
'paths' => [
'controllers' => 'app/controllers',
Expand Down
8 changes: 8 additions & 0 deletions core/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Core;

class Model extends \Illuminate\Database\Eloquent\Model
{

}
23 changes: 21 additions & 2 deletions public/cache/bb1bc898496b4ab5179c545d07564e1f65afdcb8.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php $__env->startSection('title', 'Anasayfa'); ?>

<?php $__env->startSection('content'); ?>
<form action="" method="post">
<form style="display: none" action="" method="post">
<ul>
<li>
<input type="text" value="<?=$_posts['username'] ?? null?>" class="<?php if (isset($errors['username'])): ?>has-error<?php endif; ?>" placeholder="Kullanıcı adı" name="username">
<input type="text" value="<?=$_posts['username'] ?? null?>" class="<?php if (isset($errors['username'])): ?>has-error<?php endif; ?>"
placeholder="Kullanıcı adı" name="username">
<?php if (isset($errors['username'])): ?><div class="error-msg"><?=$errors['username'][0]?></div><?php endif; ?>
</li>
<li>
Expand All @@ -20,5 +21,23 @@
</li>
</ul>
</form>

<form action="" method="post">
<textarea name="content" cols="30" class="<?php if (isset($errors['content'])): ?>has-error<?php endif; ?>" rows="5"></textarea> <br>
<?php if (isset($errors['content'])): ?><div class="error-msg"><?=$errors['content'][0]?></div><?php endif; ?>
<button type="submit">Kaydet</button>
</form>

<ul>
<?php $__currentLoopData = $posts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $post): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
<li>
#<?php echo e($post->id); ?> <br>
<?php echo e($post->content); ?> <br>
Ekleyen: <?php echo e($post->user->name); ?>

</li>
<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</ul>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/MAMP/htdocs/boilerplate/public/views/home.blade.php ENDPATH**/ ?>
22 changes: 20 additions & 2 deletions public/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
@section('title', 'Anasayfa')

@section('content')
<form action="" method="post">
<form style="display: none" action="" method="post">
<ul>
<li>
<input type="text" value="@getData('username')" class="@hasError('username')" placeholder="Kullanıcı adı" name="username">
<input type="text" value="@getData('username')" class="@hasError('username')"
placeholder="Kullanıcı adı" name="username">
@getError('username')
</li>
<li>
Expand All @@ -22,4 +23,21 @@
</li>
</ul>
</form>

<form action="" method="post">
<textarea name="content" cols="30" class="@hasError('content')" rows="5"></textarea> <br>
@getError('content')
<button type="submit">Kaydet</button>
</form>

<ul>
@foreach($posts as $post)
<li>
#{{ $post->id }} <br>
{{ $post->content }} <br>
Ekleyen: {{ $post->user->name }}
</li>
@endforeach
</ul>

@endsection

0 comments on commit 7206265

Please sign in to comment.