Arshiamohammadei
2 سال پیش توسط Arshiamohammadei مطرح شد
2 پاسخ

route لاراول

سلام دوستان
تمامی آدرس های route که تنظیم کردم کار میکنه بجز product همش میزنم خطای 404 میاد کش و همه چی هم پاک کردم ولی درست نشد
لطفا ککمککک کنیددد به شدتتت گرفتارممم
فایل web.php

<?php

use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::post('payments/notification', [\App\Http\Controllers\PaymentController::class, 'notification'])->name('payment.notification');
Route::get('payments/completed', [\App\Http\Controllers\PaymentController::class, 'completed'])->name('payment.completed');
Route::get('payments/failed', [\App\Http\Controllers\PaymentController::class, 'failed'])->name('payment.failed');
Route::get('payments/unfinish', [\App\Http\Controllers\PaymentController::class, 'unfinish'])->name('payment.unfinish');
Route::get('text', function() {
    return view('frontend.payments.success');
});
//این یکی فقط کار نمیکنه -----------------

Route::get('product/{slug}', [\App\Http\Controllers\ProductController::class, 'show'])->name('product.show');

//ا-------------
Route::get('/', [\App\Http\Controllers\HomeController::class, 'index'])->name('homepage');
Route::get('search', [\App\Http\Controllers\ShopController::class, 'search'])->name('search');
Route::get('shop/{slug?}', [\App\Http\Controllers\ShopController::class, 'index'])->name('shop.index');
Route::get('shop/tag/{slug}', [\App\Http\Controllers\ShopController::class, 'tag'])->name('shop.tag');
Route::resource('favorite', \App\Http\Controllers\FavoriteController::class)->only(['index','store','destroy']);
Route::resource('cart', \App\Http\Controllers\CartController::class)->only(['index','store','update', 'destroy']);
Route::group(['middleware' => 'auth'], function() {
    Route::get('profile', [\App\Http\Controllers\Auth\ProfileController::class, 'index'])->name('profile.index');
    Route::put('profile', [\App\Http\Controllers\Auth\ProfileController::class, 'update'])->name('profile.update');
    Route::get('orders/checkout', [\App\Http\Controllers\OrderController::class, 'process'])->name('checkout.process');
    Route::get('orders/cities', [\App\Http\Controllers\OrderController::class, 'cities']);
    Route::post('orders/shipping-cost', [\App\Http\Controllers\OrderController::class, 'shippingCost']);
    Route::post('orders/set-shipping', [\App\Http\Controllers\OrderController::class, 'setShipping']);
    Route::post('orders/checkout', [\App\Http\Controllers\OrderController::class, 'checkout'])->name('checkout');
    Route::get('orders/received/{orderId}', [\App\Http\Controllers\OrderController::class, 'received'])->name('checkout.received');
    Route::get('orders', [\App\Http\Controllers\OrderController::class, 'index'])->name('orders.index');
    Route::get('orders/{orderId}', [\App\Http\Controllers\OrderController::class, 'show'])->name('orders.show');
    Route::group(['middleware' => 'isAdmin','prefix' => 'admin', 'as' => 'admin.'], function() {
        Route::get('dashboard', [\App\Http\Controllers\Admin\DashboardController::class, 'index'])->name('dashboard.index');
        Route::resource('permissions', \App\Http\Controllers\Admin\PermissionController::class);
        Route::resource('roles', \App\Http\Controllers\Admin\RoleController::class);
        Route::resource('users', \App\Http\Controllers\Admin\UserController::class);
        Route::resource('categories', \App\Http\Controllers\Admin\CategoryController::class);
        Route::resource('tags', \App\Http\Controllers\Admin\TagController::class);
        Route::post('/products/remove-image', [\App\Http\Controllers\Admin\ProductController::class, 'removeImage'])->name('products.removeImage');
        Route::resource('products', \App\Http\Controllers\Admin\ProductController::class);
        Route::resource('reviews', \App\Http\Controllers\Admin\ReviewController::class)->only(['index','edit','update','destroy','show']);
        Route::resource('slides', \App\Http\Controllers\Admin\SlideController::class);
        Route::get('slides/{slideId}/up', [\App\Http\Controllers\Admin\SlideController::class, 'moveUp']);
        Route::get('slides/{slideId}/down', [\App\Http\Controllers\Admin\SlideController::class, 'moveDown']);
        Route::resource('orders', \App\Http\Controllers\Admin\OrderController::class)->only(['index','show','destroy']);
        Route::get('orders/{orderId}/cancel', [\App\Http\Controllers\Admin\OrderController::class, 'cancel'])->name('orders.cancel');
        Route::put('orders/cancel/{orderId}', [\App\Http\Controllers\Admin\OrderController::class, 'cancelUpdate'])->name('orders.cancelUpdate');
        Route::post('orders/complete/{orderId}', [\App\Http\Controllers\Admin\OrderController::class, 'complete'])->name('orders.complete');
        Route::resource('shipments', \App\Http\Controllers\Admin\ShipmentController::class)->only(['index','edit','update']);
        Route::get('reports/revenue', [\App\Http\Controllers\Admin\ReportController::class, 'revenue'])->name('reports.revenue');
    });
});
Auth::routes();

کد های api.php

<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::post('register', [\App\Http\Controllers\API\UserController::class, 'register']);
Route::post('login', [\App\Http\Controllers\API\UserController::class, 'login']);
Route::middleware('auth:api', 'sessions')->group(function () {
    Route::get('profile', [\App\Http\Controllers\API\UserController::class, 'getProfile']);
    Route::get('logout', [\App\Http\Controllers\API\UserController::class, 'logout']);
    Route::get('cart', [\App\Http\Controllers\API\CartController::class, 'index']);
    Route::post('cart', [\App\Http\Controllers\API\CartController::class, 'store']);
    Route::put('cart/{cart_id}', [\App\Http\Controllers\API\CartController::class, 'update']);
    Route::delete('cart/{cart_id}', [\App\Http\Controllers\API\CartController::class, 'destroy']);
    Route::delete('cart', [\App\Http\Controllers\API\CartController::class, 'clear']);
    Route::get('cart/shipping-options', [\App\Http\Controllers\API\CartController::class, 'shippingOptions']);
    Route::post('cart/set-shipping', [\App\Http\Controllers\API\CartController::class, 'setShipping']);
    Route::post('order/checkout', [\App\Http\Controllers\API\OrderController::class, 'checkout']);
});

Route::middleware('client')->group(function () {
    Route::get('product', [\App\Http\Controllers\API\ProductController::class, 'index']);
    Route::get('product/{slug}', [\App\Http\Controllers\API\ProductController::class, 'show']);
});

کد های کنترل

<?php

namespace App\Http\Controllers;

use App\Models\Product;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    public function show($slug)
    {
        $product = Product::with('media', 'category', 'tags')
            ->where('slug', $slug)
            ->withCount('media','approvedReviews')
            ->withAvg('approvedReviews', 'rating')
            ->active()
            ->hasQuantity()
            ->firstOrFail();
        $relatedProducts = Product::with('firstMedia')->whereHas('category', function ($query) use ($product) {
            $query->whereId($product->category_id);
        })
            ->where('id', '<>', $product->id)
            ->inRandomOrder()
            ->active()
            ->hasQuantity()
            ->take(4)
            ->get(['id', 'slug', 'name', 'price']);

        return view('frontend.product.show', compact('product', 'relatedProducts'));
    }
}

@MahdiMashayekhi
@FullStack
@mahdidv
@endworld
@mrahmadi


ثبت پرسش جدید
میکائیل
تخصص : برنامه نویسی سمت سرور و کلاینت
@FullStack 2 سال پیش مطرح شد
0

سلام دوست عزیز
به نظر نباید روتش مشکلی داشته باشه اوکیه این کدی که میگم رو بزن و دوباره چک کن ببین درست میشه یا نه

php artisan route:clear

مهدی
تخصص : Backend Developer
@mahdidv 2 سال پیش مطرح شد
1

وقت بخیر
ببین باید توی روت هات اولویت رو رعایت کنی product رو ببر اول سطر ببین حل میشه یا نه ؟


برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام