1
我創建了一個方法,我LessonsController獲取只有軟刪除教訓只讀取軟刪除的記錄
我沒有得到什麼應該是路線我lessoncontroller
<?php
namespace App\Http\Controllers;
use Response;
use App\lesson;
use Illuminate\Http\Request;
use App\Acme\Transformers\LessonTransformer;
use Illuminate\Support\Facades\Input;
class LessonsController extends ApiController
{
protected $lessonTransformer;
function __construct(LessonTransformer $lessonTransformer)
{
$this->lessonTransformer = $lessonTransformer;
}
//fetch all and pass a metadata 'data'
public function index()
{
$lessons = Lesson::all();
return $this->respond([
'data' => $this->lessonTransformer->transformCollection($lessons->all())
]);
}
//delete a lesson by id
public function destroy($id)
{
$dlesson = Lesson::find(input::get('id'));
if(! $dlesson) {
return $this->respondNotFound();
}
$dlesson->delete();
return $this->respondDeleted('Lesson deleted successfully');
}
public function deletedLessons()
{
$deleted_lessons = Lesson::onlyTrashed()->get();
return $this->respond([
'data' => $this->lessonTransformer->transformCollection($lessons->all())
]);
}
}
我曾嘗試與像 http://localhost:8000/api/v1/lessons/11
已刪除的記錄謝謝
如果我將'index()'替換爲'Lesson :: all()'到'Lesson :: onlyTrashed() - > get();我能做到所有這些以獲得結果,但我如何獲取在一個單獨的方法,而不是'索引()' –
你是說,完全相同的代碼在'索引()'工作,但不適用於其他方法? –
是的,我懷疑這條路線是不正確的,如果得到的api/v1 /課程我會得到所有的課程期望刪除一個很好,但要刪除的路線我應該 –