Basi c Информация
Я разработал простое приложение Laravel. И я развернул, используя Heroku.
Моя проблема
Я хочу опубликовать изображение в своем приложении, используя AWS S3.
Все настройки для S3 завершены.
Но эти ошибки появились.
Call to a member function hashName() on array
Как я могу решить эту проблему?
Мои коды
app / Http / Controllers / StoriesController. php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Story;
use App\Profile;
use Auth;
use App\Posts;
use App\History;
use App\Attachment;
use Carbon\Carbon;
use Storage;
class StoriesController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
$images = Attachment::all();
$cond_title = $request->cond_title;
if ($cond_title != '') {
$posts = Profile::where('title', $cond_title)->get();
} else {
$posts = Profile::all();
}
return view('stories.index2', compact('images','posts','cond_title'));
}
public function add()
{
return view('stories.create2');
}
public function store(Request $request)
{
$form = $request->all();
$d = new \DateTime();
$d->setTimeZone(new \DateTimeZone('Asia/Tokyo'));
$dir = $d->format('Y/m');
$path = Storage::disk('s3')->putFile('/',$form['images'],'public');
$data = $request->except('_token');
foreach ($data['images'] as $k => $v) {
$filename = '';
$attachments = Attachment::take(1)->orderBy('id', 'desc')->get();
foreach ($attachments as $attachment) {
$filename = $attachment->id + 1 . '_' . $v->getClientOriginalName();
}
unset($attachment);
if ($filename == false) {
$filename = 1 . '_' . $v->getClientOriginalName();
}
$v->storeAs($path, $filename);
$attachment_data = [
'path' => Storage::disk('s3'),
'name' => $filename
];
$a = new Attachment();
$a->fill($attachment_data)->save();
}
unset($k, $v);
return redirect('/');
}
public function delete(Request $request)
{
$images = Attachment::find($request->id);
$images->delete();
return redirect('/');
}
public function upload(Request $request)
{
$this->validate($request, [
'file' => [
'required',
'file',
'image',
'mimes:jpeg,png',
]
]);
if ($request->file('file')->isValid([])) {
$path = Storage::disk('s3')->putFile('/',$form['image'],'public');
return view('stories.index2')->with('filename', basename($path));
} else {
return redirect('/')
->back()
->withInput()
->withErrors();
}
}
}
resources / views /stories/index2.blade.php
@extends('layouts.front2')
@section('title','mainpage')
@section('content')
<link rel="stylesheet" href="{{ asset('css/main2.css') }}">
<div class="profile">
<div class="name">
@guest
<a class="nav-link2" href="{{ route('register')}}">{{ __('Create Accout!')}}</a>
@else
<a id="navbarDropdown" class="nav-link2" href="#" role="button">
{{ Auth::user()->name }}<span class="caret"></span></a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
@endguest
</div>
<div class="aboutme">
<tbody>
@foreach($posts as $profile)
<tr>
<td>{{ \Str::limit($profile->title, 100) }}</td>
<td>{{ \Str::limit($profile->body, 250) }}</td>
</tr>
<a href="{{ action('ProfileController@delete', ['id' => $profile->id]) }}">delete</a>
<a href="{{ action('ProfileController@update', ['id' => $profile->id]) }}" class="update">update</a>
@endforeach
</tbody>
<br>
</div>
</div>
<div class="new">
<div class="newtitle">
<h1>New</h1>
</div>
<div class="container1">
@foreach ($images as $image)
<img src="{{ $image->path }}" class="images" style="height: 250px; width: 250px; border-radius: 50%;">
<a href="{{ action('StoriesController@delete', ['id' => $image->id]) }}">delete</a>
@endforeach
<div class="more">
more...
</div>
</div>
</div>
{{ csrf_field() }}
@endsection