Laravel8 CRUD 처리를 사용하여 게시 앱 만들기 그 10 URL 링크
목적
구현 환경
품목
정보
OS
macOS Catalina(10.15.5)
하드웨어
MacBook Pro (13-inch, 2020, Four Thunderbolt 3 ports)
프로세서
2GHz 쿼드 코어Intel Core i5
메모리
32GB 3733MHz LPDDR4
그래픽
Intel Iris Plus Graphics 1536 MB
품목
정보
비고
PHP 버전
7.4.8
Homebrew를 사용하여이 방법으로 소개 → Mac Homebrew에서 PHP 설치
Laravel 버전
8.6.0
commposer를 사용하여이 방법으로 소개 → Mac Laravel 환경 구축
MySQL 버전
8.0.19 for osx10.13 on x86_64
Homwbrew를 사용하여이 방법으로 소개 → Mac Homebrew에서 MySQL 설치
Node.js 버전
v12.14.1
Homwbrew를 사용하여이 방법으로 소개 → Mac Homebrew에서 Node.js 설치
전제 조건
전제 정보
개요
상세
뷰 파일 편집
laravel8_crud 디렉토리에서 다음 명령을 실행하여 뷰 파일을 엽니다.
$ vi resources/views/contents/output.blade.php
아래와 같이 편집한다.
laravel8_crud/resources/views/contents/output.blade.php
@extends('layouts.app')
@section('content')
<h1>output</h1>
@foreach ($items as $item)
<hr>
@if (isset($item['file_path']))
<img src="{{asset('storage/' . $item['file_path'])}}" alt="{{asset('storage/' . $item['file_path'])}}">
@endif
{{-- 下記を修正する --}}
<p>{!! nl2br(preg_replace('/(https?:\/\/[^\s]*)/', '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $item['content'])) !!}</p>
<a href="{{route('detail', ['content_id' => $item['id']])}}">詳細</a>
<a href="{{route('edit', ['content_id' => $item['id']])}}">編集</a>
@endforeach
@endsection
laravel8_crud 디렉토리에서 다음 명령을 실행하여 뷰 파일을 엽니다.
$ vi resources/views/contents/detail.blade.php
아래와 같이 편집한다.
laravel8_crud/resources/views/contents/detail.blade.php
@extends('layouts.app')
@section('content')
<h1>detail</h1>
@if (isset($item['file_path']))
<img src="{{asset('storage/' . $item['file_path'])}}" alt="{{asset('storage/' . $item['file_path'])}}">
@endif
<p>投稿ID: {{$item['id']}}</p>
{{-- 下記を修正する --}}
<p>投稿内容: {!! nl2br(preg_replace('/(https?:\/\/[^\s]*)/', '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $item['content'])) !!}</p>
<p>投稿時間: {{$item['created_at']}}</p>
<a href="{{route('edit', ['content_id' => $item['id']])}}">編集</a>
<form action="{{route('delete')}}" method="post">
@csrf
<input type="hidden" name="id" value="{{$item['id']}}">
<input type="submit" value="削除">
</form>
@endsection
확인
laravel8_crud 디렉토리에서 다음 명령을 실행하여 로컬 서버를 시작합니다.
$ php artisan serve
브라우저에서 다음에 액세스합니다.
게시물에 "https://qiita.com/miriwo”를 입력하고 “제출”을 클릭합니다.

아래에 액세스합니다.
URL이 링크되어 있어 클릭하면 새로운 탭으로 필자의 Qiita의 화면이 표시되는 것을 확인한다.

URL 게시물의 '자세히 알아보기'를 클릭합니다.

URL이 링크되어 있어 클릭하면 새로운 탭으로 필자의 Qiita의 화면이 표시되는 것을 확인한다.

Reference
이 문제에 관하여(Laravel8 CRUD 처리를 사용하여 게시 앱 만들기 그 10 URL 링크), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/miriwo/items/5652577b5186b9c64c6b텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)