我正在Windows 7 OS上的Laravel项目上工作,我收到403 Access禁止页面,提示您无权访问所请求的目录。当我尝试访问项目/产品页面时,没有索引文档或目录受到了保护。当我访问项目页面(主页)或项目/产品/创建页面时,一切正常,仅当我在项目/产品上或提交表单上载产品时,我才会收到错误消息。我编辑了该文件夹和文件的权限以拥有完全控制权,并且还尝试像其他人一样编辑httpd-vhosts.conf并遇到类似问题,然后重新启动apache,但无济于事。感谢您的帮助,这是我的代码:
index.blade.php:
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h1>Products</h1>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('products.create') }}"> Upload Product</a>
</div>
</div>
</div>
<table class="table table-bordered">
<tr>
<thead>
<th>ID</th>
<th>Files</th>
<th>Product Name</th>
<th>Owner Of The Product</th>
</thead>
</tr>
<tbody>
@foreach ($products as $product)
<tr>
<td>{{ $product->id }}</td>
<td>{{ $product->files }}</td>
<td>{{ $product->name }}</td>
<td>
@foreach ($product->users as $user)
{{ $user->name }}
@endforeach
</td>
<td>
<form action="{{ route('products.destroy', $product->id) }}" method="POST">
<a class="btn btn-info" href="{{ route('products.show', $product->id) }}">Show</a>
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
ProductController.php:
<?php
namespace App\Http\Controllers;
use App\Product;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class ProductController extends Controller
{
public function index()
{
$products = Product::with('users')->get();
return view('products.index', compact('products'));
}
public function create()
{
return view('products.create');
}
public function store(Request $request)
{
DB::beginTransaction();
try {
if ($file = $request->file('files')) {
$name = $file->getClientOriginalName();
if ($file->move('products', $name)) {
$product = new Product();
$product->files = $name;
$product->save();
$product->users()->attach(Auth::id());
}
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
}
return redirect()->route('products.index');
}
public function show(Product $product)
{
return view('products.show', compact('product'));
}
public function destroy(Product $product)
{
$product->users()->detach();
$product->delete();
return redirect()->route('products.index');
}
}
httpd-vhosts.conf:
<VirtualHost project.devel:80>
DocumentRoot "C:\xampp\htdocs\project\public"
ServerAdmin project.devel
<Directory "C:\xampp\htdocs\project\public">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
主机:
localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 project.devel