Skip to content

Commit 415d325

Browse files
rfaystasadev
authored andcommitted
Add messages table and view and route
1 parent bd44e4a commit 415d325

File tree

10 files changed

+149
-75
lines changed

10 files changed

+149
-75
lines changed

README.md

+20-66
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,20 @@
1-
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>
2-
3-
<p align="center">
4-
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
5-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
6-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
7-
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
8-
</p>
9-
10-
## About Laravel
11-
12-
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:
13-
14-
- [Simple, fast routing engine](https://laravel.com/docs/routing).
15-
- [Powerful dependency injection container](https://laravel.com/docs/container).
16-
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
17-
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
18-
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
19-
- [Robust background job processing](https://laravel.com/docs/queues).
20-
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).
21-
22-
Laravel is accessible, powerful, and provides tools required for large, robust applications.
23-
24-
## Learning Laravel
25-
26-
Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework.
27-
28-
You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch.
29-
30-
If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.
31-
32-
## Laravel Sponsors
33-
34-
We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).
35-
36-
### Premium Partners
37-
38-
- **[Vehikl](https://vehikl.com/)**
39-
- **[Tighten Co.](https://tighten.co)**
40-
- **[WebReinvent](https://webreinvent.com/)**
41-
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
42-
- **[64 Robots](https://64robots.com)**
43-
- **[Curotec](https://www.curotec.com/services/technologies/laravel/)**
44-
- **[Cyber-Duck](https://cyber-duck.co.uk)**
45-
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
46-
- **[Jump24](https://jump24.co.uk)**
47-
- **[Redberry](https://redberry.international/laravel/)**
48-
- **[Active Logic](https://activelogic.com)**
49-
- **[byte5](https://byte5.de)**
50-
- **[OP.GG](https://op.gg)**
51-
52-
## Contributing
53-
54-
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).
55-
56-
## Code of Conduct
57-
58-
In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).
59-
60-
## Security Vulnerabilities
61-
62-
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [[email protected]](mailto:[email protected]). All security vulnerabilities will be promptly addressed.
63-
64-
## License
65-
66-
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
1+
# test-laravel for DDEV testing only:
2+
3+
- Clone this repo, add upstream `git remote add upstream https://github.com/laravel/laravel`
4+
- Rebase the default branch `ddev-automated-test` onto the latest tag from `upstream`, resolve conflicts
5+
- Use the [latest Laravel quickstart](https://ddev.readthedocs.io/en/latest/users/quickstart/#laravel) for this repo, do not commit `.ddev`:
6+
```bash
7+
ddev config --project-type=laravel --docroot=public
8+
ddev start
9+
rm -rf .env composer.lock vendor
10+
ddev composer install
11+
ddev composer run-script post-root-package-install
12+
ddev composer run-script post-create-project-cmd
13+
git add .env composer.lock vendor -f
14+
```
15+
- Download `db.sql.tar.gz` from the latest release and run `ddev import-db --file=db.sql.tar.gz`
16+
- Run Laravel migrations `ddev php artisan migrate`
17+
- Export the db `mkdir -p .tarballs && ddev export-db --gzip=false --file=.tarballs/db.sql && tar -czf .tarballs/db.sql.tar.gz -C .tarballs db.sql`
18+
- Run `git push`, create a new release adding `.tarballs/db.sql.tar.gz` as an asset
19+
- Update the URLs in `ddev/ddev` for the new release (e.g. if the old release was `10.0.5.2` and the new release is `11.0.1.1`, then search for this string in the `ddev/ddev` and replace it with `11.0.1.1`)
20+
- Rerun the tests for Laravel `GOTEST_SHORT=9 make testfullsitesetup`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Message;
6+
use Illuminate\Http\Request;
7+
8+
class MessagesController extends Controller
9+
{
10+
public function index()
11+
{
12+
$messages = Message::all();
13+
return view('messages.index', compact('messages'));
14+
}
15+
16+
public function store(Request $request)
17+
{
18+
$request->validate([
19+
'content' => 'required',
20+
]);
21+
22+
Message::create($request->all());
23+
return redirect()->route('messages.index')->with('success', 'Message saved successfully.');
24+
}
25+
}

app/Models/Message.php

+13
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 Message extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $fillable = ['content'];
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateMessagesTable extends Migration
8+
{
9+
public function up()
10+
{
11+
Schema::create('messages', function (Blueprint $table) {
12+
$table->id();
13+
$table->text('content');
14+
$table->timestamps();
15+
});
16+
}
17+
18+
public function down()
19+
{
20+
Schema::dropIfExists('messages');
21+
}
22+
}

database/seeders/DatabaseSeeder.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ class DatabaseSeeder extends Seeder
1313
*/
1414
public function run(): void
1515
{
16-
// User::factory(10)->create();
17-
18-
User::factory()->create([
19-
'name' => 'Test User',
20-
'email' => '[email protected]',
21-
]);
16+
$this->call(MessagesTableSeeder::class);
2217
}
2318
}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use Illuminate\Database\Seeder;
6+
use App\Models\Message;
7+
8+
class MessagesTableSeeder extends Seeder
9+
{
10+
/**
11+
* Run the database seeds.
12+
*
13+
* @return void
14+
*/
15+
public function run()
16+
{
17+
$messages = [
18+
'First message.',
19+
'Second message.',
20+
'Third message.',
21+
];
22+
23+
foreach ($messages as $message) {
24+
Message::create(['content' => $message]);
25+
}
26+
}
27+
}

public/static/index.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Static HTML Page</title>
5+
</head>
6+
<body>
7+
<h1>Static HTML Page</h1>
8+
<p>This is a static HTML page in a Laravel project.</p>
9+
<img src="/static/sample-1.jpg" alt="Sample Image" width="20%" height="20%">
10+
</body>
11+
</html>

public/static/sample-1.jpg

3.4 MB
Loading
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Simple Laravel App</title>
5+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
6+
</head>
7+
<body>
8+
<div class="container mt-5">
9+
<h2 class="mb-4">Messages</h2>
10+
<form action="{{ route('messages.store') }}" method="POST">
11+
@csrf
12+
<div class="form-group">
13+
<textarea name="content" class="form-control" placeholder="Write a message..."></textarea>
14+
</div>
15+
<button type="submit" class="btn btn-primary">Submit</button>
16+
</form>
17+
<hr>
18+
<h3>Stored Messages</h3>
19+
<ul>
20+
@foreach ($messages as $message)
21+
<li>{{ $message->content }}</li>
22+
@endforeach
23+
</ul>
24+
</div>
25+
</body>
26+
</html>
27+

routes/web.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4+
use App\Http\Controllers\MessagesController;
45

5-
Route::get('/', function () {
6-
return view('welcome');
7-
});
6+
Route::get('/', [MessagesController::class, 'index'])->name('messages.index');
7+
Route::post('/', [MessagesController::class, 'store'])->name('messages.store');

0 commit comments

Comments
 (0)