【发布时间】:2016-07-18 02:13:27
【问题描述】:
我有两个方法 show 和 index 我在 index 方法上有一个项目列表,当用户单击它时,它会将她带到另一个页面,其中包含一些属于该 id 的数据。我不想这样做,而是想使用 jquery 在同一页面上加载数据。我的index.blade.php 视图中有以下内容。我如何在 laravel 中实现这一点?
@foreach ($categories as $category)
<div class="body">
<h4><a style="text-decoration: none; " href="{{ URL::route('category.show', $category->id) }}">{{$category->name}}</a></h4>
</div>
@endforeach
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use illuminate\HttpResponse;
use App\Http\Requests\todolistRequest;
use App\Http\Requests\CreateCategoryRequest;
use App\Http\Requests;
use App\Companylist;
use App\Category;
use Illuminate\Support\Facades\DB;
class CategoryController extends Controller
{
public function create(){
return view('category.create');
}
public function index(){
$categories=Category::all();
return view('category.index',compact('categories'));
}
public function store(CreateCategoryRequest $request){
$category = new Category($request->all());
$category->save();
return \Redirect::route('category.create')->with('message', 'Your list has been created!');
}
public function show($id)
{
$category = Category::findOrFail($id)->companylist()->get();
$cat=Category::findOrFail($id);
// this my route
Route::resource('category','CategoryController');
return view('category.show')->with('category', $category)->with('cat',$cat);
}
// }
【问题讨论】:
-
“shift”键是键盘左下角的那个长按钮。 Use this regularly,它大大提高了您获得有用答案的机会。