Ⅰ 怎麼利用ajax調用後台返回的圖片輪播的介面
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class BannerController extends Controller
{
public function BannerCreate(Request $request)
{
$file = $request->file('photo');//獲取圖片
$theme = $request->theme;//主題
$status = $request->status;//狀態
$allowed_extensions = ["png", "jpg", "gif"];
if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
return response()->json([
'status' => false,
'message' => '只能上傳 png | jpg | gif格式的圖片'
]);
}
if ($request->hasFile('photo')) {
}
$destinationPath = 'storage/uploads/';
$extension = $file->getClientOriginalExtension();
$fileName = str_random(10).'.'.$extension;
$file->move($destinationPath, $fileName);
return Response()->json(
[
'status' => true,
'pic' => asset($destinationPath.$fileName),
'isMake' => $status,
'message' => '新增成功!'
]
);
}
}