v0.0.2 You can now make post and store it in the database.

This commit is contained in:
Victor
2021-06-02 09:01:51 +02:00
parent dfb9103157
commit d276aed27b
11 changed files with 78 additions and 10 deletions
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace Backend\Model;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Post extends Eloquent{
protected $fillable = [
'title','description'
];
}
@@ -1,5 +1,7 @@
<?php
namespace Backend\Model;
use Illuminate\Database\Eloquent\Model as Eloquent;
class User extends Eloquent{
+1
View File
@@ -0,0 +1 @@
<?php
+1
View File
@@ -1,6 +1,7 @@
<?php
require_once "../../bootstrap.php";
use Backend\Model\User;
use Illuminate\Support\Str;
session_start();
+27
View File
@@ -0,0 +1,27 @@
<?php
//require our bootstrap file for database connection
require "../../bootstrap.php";
use Backend\Model\Post;
//Chek if the user did press the button on the home pages
if(isset($_POST['createPost'])){
//Grep the data from post
$title = $_POST['title'];
$description = $_POST['description'];
//Create a new initialize
$post = new Post();
//Call the Post class and save the user data to the database
$post->title = $title;
$post->description = $description;
//Call the save function.
if(!$post->save()){
echo "Failed to save the post";
exit();
}else{
echo "Post has been saved";
}
}
+11
View File
@@ -0,0 +1,11 @@
<?php
require "../../bootstrap.php";
use Illuminate\Database\Capsule\Manager as Capsule;
Capsule::schema()->create('posts', function ($table) {//Note til mig selv, husk at din database table skal ende med "s" hvis du faa en lang fejl besked
$table->increments('id');
$table->string('title');
$table->longtext('description');
$table->timestamps();
});
+3 -2
View File
@@ -1,5 +1,6 @@
<?php
require "user_migration.php";
echo "Done";
//require "user_migration.php";
//require "post_migration.php";
echo "Nothing required/Enabled ";