找不到Laravel API

时间:2019-03-20 06:43:29

标签: php laravel api

我正在尝试测试我的api,因此,我不需要对api进行身份验证,我想要做的就是与api共享已发布的帖子,但是我得到了404页面。

代码

controller

<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Post;

class PostController extends Controller
{
    public function index(){
        return Post::orderby('id', 'desc')->where('status', '=', '1')->get();
    }

    public function single($slug){
        return Post::where('slug', $slug)->where('status', '=', '1')->firstOrFail();
    }
}

api.php(路由文件夹)

Route::get('posts', 'API\PostController@index');
Route::get('posts/{slug}', 'API\PostController@single');

我尝试使用以下网址访问我的api帖子:http://newapp.test/api/posts,它返回了404错误。

有什么想法吗?

更新

api.php

<?php

use Illuminate\Http\Request;

// Route::middleware('auth:api')->get('/user', function (Request $request) {
//     return $request->user();
// });

Route::get('posts', 'API\PostController@index');
Route::get('posts/{slug}', 'API\PostController@single');

2 个答案:

答案 0 :(得分:0)

保留所有内容,并保留 RUN命令

php artisan route:clear 

答案 1 :(得分:0)

运行命令Traceback (most recent call last): File "selTest.py", line 88, in <module> csc() File "selTest.py", line 44, in csc worksheet.write(alpah_list[indexOfAlpha] + str(indexOfSheet), str(driver.find_element(By.CSS_SELECTOR("input[class = 'edited_field ng-pristine ng-untouched ng-valid ng-not-empty'][ng-model = 'tab.content.site.name']")))) TypeError: 'str' object is not callable Shahans-MacBook-Pro:WebScraping Shahan$ python3 selTest.py Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlsxwriter/worksheet.py", line 469, in _write f = float(token) TypeError: float() argument must be a string or a number, not 'WebElement' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "selTest.py", line 88, in <module> csc() File "selTest.py", line 44, in csc worksheet.write(alpah_list[indexOfAlpha] + str(indexOfSheet), driver.find_element_by_css_selector('input.edited_field.ng-pristine.ng-untouched.ng-valid.ng-not-empty')) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlsxwriter/worksheet.py", line 67, in cell_wrapper return method(self, *args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlsxwriter/worksheet.py", line 408, in write return self._write(row, col, *args) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlsxwriter/worksheet.py", line 474, in _write raise TypeError("Unsupported type %s in write()" % type(token)) TypeError: Unsupported type <class 'selenium.webdriver.remote.webelement.WebElement'> in write() 。它将显示您应用程序中可用路线的列表。这样,您可以首先验证现有路线和您要访问的路线。