Skip to content

Commit ade967a

Browse files
committed
init project
1 parent 43b7b6f commit ade967a

Some content is hidden

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

62 files changed

+11237
-4
lines changed

.editorconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2
16+
17+
[docker-compose.yml]
18+
indent_size = 4

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DB_CONNECTION=mariadb
2+
DB_HOST=127.0.0.1
3+
DB_PORT=3306
4+
DB_DATABASE=laravel_php_mariadb_demo
5+
DB_USERNAME=root
6+
DB_PASSWORD=

.gitattributes

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* text=auto eol=lf
2+
3+
*.blade.php diff=html
4+
*.css diff=css
5+
*.html diff=html
6+
*.md diff=markdown
7+
*.php diff=php
8+
9+
/.github export-ignore
10+
CHANGELOG.md export-ignore
11+
.styleci.yml export-ignore

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/.phpunit.cache
2+
/node_modules
3+
/public/build
4+
/public/hot
5+
/public/storage
6+
/storage/*.key
7+
/storage/pail
8+
/vendor
9+
.env
10+
.env.backup
11+
.env.production
12+
.phpactor.json
13+
.phpunit.result.cache
14+
Homestead.json
15+
Homestead.yaml
16+
npm-debug.log
17+
yarn-error.log
18+
/auth.json
19+
/.fleet
20+
/.idea
21+
/.nova
22+
/.vscode
23+
/.zed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# Laravel PHP MariaDB Demo
22

3+
## Prerequisites
4+
5+
** PR (Phhp 9.x or higher)
6+
** Composer (Package Manager)
7+
** MariaDB 10.x running on MacOS
8+
39
## Installation
410

5-
### 1. Install PHP, Composer, and MariaDB
6-
```
7-
bash setup-mac/macsetup.sh
11+
### 1. Clone the repository:
12+
13+
```sh
14+
git clone https://github.com/serverlesssalad/laravel-php-mariadb-demo.git
15+
cd laravel-php-mariadb-demo
816
```
917

1018
### 2. Configure `.env` file:
@@ -31,5 +39,10 @@ php artisan migrate
3139
php artisan serve
3240
```
3341

34-
Access Test: http://127.0.0.1:8000/api/words
42+
## API Test
43+
44+
### GET words
45+
```sh
46+
curl -X POST http://127.0.0.1:8000/api/words
47+
```
3548

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
abstract class Controller
6+
{
7+
//
8+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use App\Models\Word;
7+
8+
class WordController extends Controller
9+
{
10+
public function index()
11+
{
12+
return response()->json(Word::all());
13+
}
14+
15+
public function store(Request $request)
16+
{
17+
$request->validate(['word' => 'required|string|unique:words,word']);
18+
$word = Word::create($request->only('word'));
19+
return response()->json($word, 201);
20+
}
21+
22+
public function show($id)
23+
{
24+
$word = Word::findOrFail($id);
25+
return response()->json($word);
26+
}
27+
28+
public function update(Request $request, $id)
29+
{
30+
$word = Word::findOrFail($id);
31+
$request->validate(['word' => 'required|string|unique:words,word']);
32+
$word->update($request->only('word'));
33+
return response()->json($word);
34+
}
35+
36+
public function destroy($id)
37+
{
38+
Word::destroy($id);
39+
return response()->json(['message' => 'Word deleted successfully']);
40+
}
41+
}

app/Models/User.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
// use Illuminate\Contracts\Auth\MustVerifyEmail;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
7+
use Illuminate\Foundation\Auth\User as Authenticatable;
8+
use Illuminate\Notifications\Notifiable;
9+
10+
class User extends Authenticatable
11+
{
12+
/** @use HasFactory<\Database\Factories\UserFactory> */
13+
use HasFactory, Notifiable;
14+
15+
/**
16+
* The attributes that are mass assignable.
17+
*
18+
* @var list<string>
19+
*/
20+
protected $fillable = [
21+
'name',
22+
'email',
23+
'password',
24+
];
25+
26+
/**
27+
* The attributes that should be hidden for serialization.
28+
*
29+
* @var list<string>
30+
*/
31+
protected $hidden = [
32+
'password',
33+
'remember_token',
34+
];
35+
36+
/**
37+
* Get the attributes that should be cast.
38+
*
39+
* @return array<string, string>
40+
*/
41+
protected function casts(): array
42+
{
43+
return [
44+
'email_verified_at' => 'datetime',
45+
'password' => 'hashed',
46+
];
47+
}
48+
}

app/Models/Word.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Word extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['word'];
13+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace App\Providers;
4+
5+
use Illuminate\Support\ServiceProvider;
6+
7+
class AppServiceProvider extends ServiceProvider
8+
{
9+
/**
10+
* Register any application services.
11+
*/
12+
public function register(): void
13+
{
14+
//
15+
}
16+
17+
/**
18+
* Bootstrap any application services.
19+
*/
20+
public function boot(): void
21+
{
22+
//
23+
}
24+
}

0 commit comments

Comments
 (0)