php -v

 

composer create-project --preper-dist laravel/laravel <project-name>

 

php artisan serve

 

php artisan make:migration create_Boards_table --create=Boards

 

php artisan migrate

 

 

/database/migrations/2024_05_03_000000_create_boards_table.php 

up() 내용 수정

 public function up(): void
    {
        Schema::create('sw_histories', function (Blueprint $table) {
        	$table->id();
            $table->timestamps();
            $table->date('wtime')->nullable();
            $table->string('title')->nullable();
            $table->text('note')->nullable();
            $table->string('uname')->nullable();
            $table->integer('cnt')->nullable();
		});
	}

 

php artisan migrate

 

php artisan make:controller BoardsController --resources --model=Board

 

(인증 브리즈)

composer require laraval/breeze -dev
php artisan breeze:install
php artisan migrate
npm install
npm install && run dev

(선택)

App/Providers/RouteServiceProvider.php

HOME='/';

HOME='/dashboard';

 

/routes/web.php

<?php
use App\Http\Controllers\BoardsController;
use Illuminate\Support\Facades\Route;
use App\Models\board;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

Route::get('/', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

require __DIR__.'/auth.php';

//Route::resource('board', BoardsController::class);
Route::get('/board', [BoardsController::class, 'index'])->name('board.index');
Route::get('/board/create', [BoardsController::class, 'create'])->name('board.create');
Route::post('/board/store', [BoardsController::class, 'store'])->name('board.store');

 

'PHP' 카테고리의 다른 글

[PHP] 게시판 만들기 (mysql)  (0) 2024.03.04

 

board_write.php

<form id="boardwrite" name="boardwrite" method="POST" action="board_write_ok.php">
<table class="table board_news nborder">
<tr> <!-- STATUS REVISION DATE -->
<th class="text_white">TITLE</th>
<td class="text_white"><input name="title" id="title" type="text" placeholder="TITLE"></td>
</tr>
<tr>
<th class="text_white">CONTENT</th>
<td class="text_white"><textarea name="content" id="content" cols="30" rows="10" placeholder="CONTENT"></textarea></td>
</tr>
<tr>
<th class="text_white">STATUS</th>
<td class="text_white"><input name="link" id="link" type="text" placeholder="LINK"></td>
</tr>
<tr>
<th class="text_white">DOCUMENT NUMBER</th>
<td class="text_white"><input name="dnum" id="dnum" type="text" placeholder="DOCUMENT NUM"></td>
</tr>
<tr>
<th class="text_white">CATEGORY</th>
<td class="text_white"><input name="cat" id="cat" type="text" placeholder="CATEGORY"></td>
</tr>
<tr>
<th class="text_white">PASSWORD</th>
<td class="text_white"><input name="pw" id="pw" type="password" placeholder="pw"></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">WRITE</button></td>
</tr>
</table>
</form>
 


<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<script>

function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");

if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}

document.boardwrite.submit();
}
</script>

 

db.php

<?php
header('Content-Type: text/html; charset=utf-8'); // utf-8인코딩
// 데이터베이스 연결 설정
// $host = "localhost";
// $username = "your_username";
// $password = "your_password";
// $dbname = "your_dbname";

$db = new mysqli($host, $username ,$password ,$dbname);
$db->set_charset("utf8");

function mq($sql)
{
global $db;
return $db->query($sql);
}

 

board_write_ok.php

<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";

$title = $_POST['title'];
$content = $_POST['content'];
$link = $_POST['link'];
$dnum = $_POST['dnum'];
$cat = $_POST['cat'];
$pw = $_POST['pw'];
//$date = now();
 
$sql = mq("insert into board_news (title, content, link, dnum, cat) values ('".$title."', '".$content."', '".$link."', '".$dnum."', '".$cat."');");
if ($sql){
echo "<script>alert('SEND COMPLETE.');window.location.replace('board_list.php');</script>";
 
}else{
echo "<script>alert('FAILED.');window.location.replace('board_list.php');</script>";
}
?>

 

 

board_list.php

<?php
include  $_SERVER['DOCUMENT_ROOT'] . "/db.php";
?>
 
<table class="table board_news">
 
<tr>
<th class="text_white left">#</th>
<th class="text_white">TITLE</th>
<th class="text_white">WRITER</th>
<th class="text_white right">DATE</th>
</tr>
 
<!--FORUM STANDARD STATUS REVISION DATE -->
<?
$sql = mq("select * from board_news order by id desc;");
$n=1;
while ($board = $sql->fetch_array()) {
 
?>

<tr>
<td class="pt-3 left text_white left"><?php echo $n; ?></td>
<td class="pt-3 text_white"><a href="board_view.php?idx=<?= $board['id'] ?>" target="_self"><?php echo $board['title']; ?></a></td>
<td class="text_white center">관리자</td>
<td class="text_white right"><?php echo $board['date']; ?></td>
</tr>
<?
$n=$n+1;
}
?>
<tr><td colspan="3">
<button class="btn right" onclick="location.href='board_write.php';">WRITE</button></td>
</tr>
</table>
 
 

 

board_view.php

<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";

$idx = $_GET['idx'];
$sql = mq("SELECT * FROM board_news where id = ".$idx.";");
$news = $sql->fetch_array();
?>
 
<form id="boardwrite" name="boardwrite" method="POST" action="board_write_ok.php">
<table class="table board_news">
<tr> <!-- STATUS REVISION DATE Document Num DOCUMENT NUM-->
<th class="text_white" style="border:none !important;">TITLE</th>
<td class="text_white left" style="border:none !important;"><?= $news['title'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">CONTENT</th>
<td class="text_white left" style="border:none !important;"><?= $news['content'] ?></textarea></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">STATUS</th>
<td class="text_white left" style="border:none !important;"><?= $news['link'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">DOCUMENT NUMBER</th>
<td class="text_white left" style="border:none !important;"><?= $news['dnum'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">CATEGORY</th>
<td class="text_white left" style="border:none !important;"><?= $news['cat'] ?></td>
</tr>
<tr>
<th class="text_white" style="border:none !important;">REVISION DATE</th>
<td class="text_white left" style="border:none !important;"><?= $news['date'] ?></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="location.href='board_list.php';">LIST</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_del.php?idx=<?=$idx?>'">DELETE</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_mod.php?idx=<?=$idx?>'">MODIFY</button></td>
</tr>
</table>
</form>
 
<script>

function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");

if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}

document.boardwrite.submit();
}
</script>

 

 

board_mod.php

<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";

$idx = $_GET['idx'];
$sql = mq("SELECT * FROM board_news where id = ".$idx.";");
$news = $sql->fetch_array();
?>
 
<form id="boardwrite" name="boardwrite" method="POST" action="board_mod_ok.php">
<input type="hidden" name="idx" id="idx" value="<?=$news['id']?>">
<table class="table board_news nborder">
<!-- STATUS REVISION DATE -->
<tr>
<th class="text_white">TITLE</th>
<td class="text_white"><input name="title" id="title" type="text" value="<?= $news['title'] ?>"></td>
</tr>
<tr>
<th class="text_white">CONTENT</th>
<td class="text_white"><textarea name="content" id="content" cols="30" rows="10"><?= $news['content'] ?></textarea></td>
</tr>
<tr>
<th class="text_white">STATUS</th>
<td class="text_white"><input name="link" id="link" type="text" value="<?= $news['link'] ?>"></td>
</tr>
<tr>
<th class="text_white">DOCUMENT NUMBER</th>
<td class="text_white"><input name="dnum" id="dnum" type="text" value="<?= $news['dnum'] ?>"></td>
</tr>
<tr>
<th class="text_white">CATEGORY</th>
<td class="text_white"><input name="cat" id="cat" type="text" value="<?= $news['cat'] ?>"></td>
</tr>
<tr>
<th class="text_white">PASSWORD</th>
<td class="text_white"><input name="pw" id="pw" type="password" value=""></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">MODIFY</button>
<button type="button" class="btn right mr-2" onclick="location.href='board_list.php';">LIST</button></td>
</tr>
</table>
</form>
 


<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

<script>

function confirm() {
var title = document.getElementById("title");
var content = document.getElementById("content");
var link = document.getElementById("link");

if (title.value == '') {
alert("Please Insert Title.");
title.focus();
return false;
}
if (content.value == '') {
alert("Please Insert Content.");
content.focus();
return false;
}

document.boardwrite.submit();
}
</script>

 

board_mod_ok.php

<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";

$idx = $_POST['idx'];
$title = $_POST['title'];
$content = $_POST['content'];
$link = $_POST['link'];
$dnum = $_POST['dnum'];
$cat = $_POST['cat'];
$pw = $_POST['pw'];
 
$sql = mq("update board_news set title='".$title."', content='".$content."', link='".$link."', dnum='".$dnum."', cat='".$cat."' where id=".$idx.";");
if ($sql){
echo "<script>alert('UPDATE COMPLETE.');window.location.replace('board_list.php');</script>";
}else{
echo "<script>alert('UPDATE FAILED.');window.location.replace('board_list.php');</script>";
}
?>

 

board_del.php

<?php
$idx = $_GET['idx'];
?>
 
 
<form id="boardwrite" name="boardwrite" method="POST" action="board_del_ok.php">
<input type="hidden" name="idx" id="idx" value="<?=$idx?>">
<table class="table board_news nborder">
<tr>
<th class="text_white">ADMIN-ID</th>
<td class="text_white"><input name="adminid" id="adminid" type="text" placeholder="admin id"></td>
</tr>
<tr>
<th class="text_white">ADMIN-PASSWORD</th>
<td class="text_white"><input name="adminpw" id="adminpw" type="password" placeholder="admin password"></td>
</tr>
<tr><td colspan="2">
<button type="button" class="btn right" onclick="confirm();">ADMIN CONFIRM</button></td>
</tr>
</table>
</form>
<script>

function confirm() {
var adminid = document.getElementById("adminid");
var adminpw = document.getElementById("adminpw");
 
if (adminid.value == '') {
alert("Please Insert ID.");
adminid.focus();
return false;
}
if (adminpw.value == '') {
alert("Please Insert PASSWORD.");
adminpw.focus();
return false;
}

document.boardwrite.submit();
}
</script>

 

board_del_ok.php

<?php
include $_SERVER['DOCUMENT_ROOT'] . "/db.php";

$idx = $_POST['idx'];
$adminid = $_POST['adminid'];
$adminpw = $_POST['adminpw'];

if ($adminid == '**' && $adminpw == '**'){
$sql = mq("delete from board_news where id=".$idx.";");
if ($sql){
echo "<script>alert('DELETE COMPLETE.');window.location.replace('board_list.php');</script>";
}else{
echo "<script>alert('DELETE FAILED.');window.location.replace('board_list.php');</script>";
}
} else {
echo "<script>alert('PLEASE CHECK ADMIN-SIGN-IN.');window.location.replace('board_list.php');</script>";
}


?>

 

myfunc.php

<?php
header('Content-Type: text/html; charset=utf-8'); // utf-8인코딩
function strChk($string){
$t_string = str_replace("'", "\'", $string);
//$t_string = str_replace("/", "###", $t_string);
//$t_string = str_replace(";", ":", $t_string);
return $t_string;
}
function strRoll($string){
//$t_string = str_replace("###", "'", $string);
$t_string = $string;
return $t_string;
}

?>

 

'PHP' 카테고리의 다른 글

라라벨 dev 시작하기  (0) 2024.05.03

+ Recent posts