这是我的控制器:
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class RegisterController extends Controller
{
public function register(Request $request)
{
dd('aa');
}
}
Run Code Online (Sandbox Code Playgroud)
如屏幕截图所示,该类存在并且位于正确的位置:
我的api.php路线:
Route::get('register', 'Api\RegisterController@register');
Run Code Online (Sandbox Code Playgroud)
当我register使用 Postman 到达我的路线时,它给了我以下错误:
目标类 [Api\RegisterController] 不存在。
更新:
多亏了答案,我才能修复它。我决定为此路由使用完全限定的类名,但还有其他选项,如答案中所述。
Route::get('register', 'App\Http\Controllers\Api\RegisterController@register');
Run Code Online (Sandbox Code Playgroud) 即使我没有新的提交推送,如何强制在服务器上git运行post-receive挂钩?
我使用git自动将网站部署到服务器.我在服务器的受保护区域的裸回购和post-receive,检查出对某些文件的内容和系统复制到一个钩子public_html文件夹.(受本教程启发)
我厌倦了post-receive在服务器上手动修改钩子,所以我的post-receive钩子现在实际上从repo复制了自己的新版本:
#!/bin/sh
rm -rf ~/../protected/*
GIT_WORK_TREE=~/../protected git checkout -f
# Rewrite over this file with any updates from the post-receive file
cp ~/../protected/post-receive hooks/post-receive
# Delete public_html
# Copy stuff public_html
Run Code Online (Sandbox Code Playgroud)
当然,问题是新的post-receive钩子永远不会运行.一个看似简单的解决方案只是再次推动,但现在一切都已经是最新的.这很烦人,因为每次我更新post-receive钩子时都需要我伪造一个新的提交.有没有办法调用post-receive钩子而不伪造提交或ssh进入?
git push
git push -f
Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel的功能firstOrNew()来创建新用户或查找和更新现有用户.
在创建对象之后,如果它之前存在或者它是新对象,我怎么知道?
这个想法是这样的:
$user = \App\User::firstOrNew([
'email' => $userData->getEmail(),
'name' => $userData->getName(),
]);
if ($user->new) { // some way to check
// user was created now
} else {
//user already existed
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的Laravel升级5.5为5.6.我已按照laravel网站的说明进行操作,但我收到此错误:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package laravel/framework 5.6.* is satisfiable by laravel/framework[5.6.x-dev] but these conflict with your requirements or minimum-stability.
Run Code Online (Sandbox Code Playgroud)
所以,我改变了我的composer.json文件并添加了2行:**"minimum-stability": "dev", "prefer-stable": true,**基于这个 laracast讨论的第一个答案.
一切似乎工作得很好,直到我得到另一个错误:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 0 installs, 6 updates, 0 removals
- Updating sebastian/diff (2.0.1 => 3.0.0): Downloading (100%)
- Updating phpunit/phpunit-mock-objects (5.0.6 …Run Code Online (Sandbox Code Playgroud) 我试图在Laravel 5中创建mysql表.我创建了一个/project/database/migrations名为的文件users.php:
[...]
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->string('username');
$table->string('fullname');
$table->int('number');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
[...]
Run Code Online (Sandbox Code Playgroud)
然后我尝试在project-folder中运行这些命令:
$ php artisan migrate
$ php artisan migrate:install
$ php artisan migrate --pretend
Run Code Online (Sandbox Code Playgroud)
它们都没有返回任何输出,也没有创建表.要填充的数据库存在.
我正在寻找解决方案...它变得非常令人沮丧.在Laravel彻底安装Lumen之后,我根本无法访问"/"路线.当我尝试时,它会抛出一个错误:
NotFoundHttpException in RoutesRequests.php line 443:
in RoutesRequests.php line 443
at Application->handleDispatcherResponse(array('0')) in RoutesRequests.php line 380
at Application->Laravel\Lumen\Concerns\{closure}() in RoutesRequests.php line 629
at Application->sendThroughPipeline(array(), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28
Run Code Online (Sandbox Code Playgroud) 从我所看到的,现在这应该很简单.
我希望能够从数据库中删除多个记录.我有id我想删除的所有记录.我resource.destroy使用逗号分隔的id列表(id具有postgres类型uuid)来调用路由,如下所示:
Request URL:http://foo.app/products/62100dd6-7ecf-4870-aa79-4b132e60c904,c4b369f1-d1ef-4aa2-b4df-b9bc300a4ff5
Request Method:DELETE
Run Code Online (Sandbox Code Playgroud)
另一方面,我的控制器动作如下:
public function destroy($id)
{
try {
$ids = explode(",", $id);
$org->products()->find($ids)->delete();
}
catch(...) {
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误:
BadMethodCallException in Macroable.php line 81:
Method delete does not exist.
in Macroable.php line 81
at Collection->__call('delete', array()) in ProductsController.php line 251
at Collection->delete() in ProductsController.php line 251
at ProductsController->destroy('62100dd6-7ecf-4870-aa79-4b132e60c904,c4b369f1-d1ef-4aa2-b4df-b9bc300a4ff5')
Run Code Online (Sandbox Code Playgroud)
我已经验证了find()返回products匹配指定ID 的集合.
我错过了什么?
PS:1.该模型与其他模型Product有几种belongsTo关系.2. product.destroy代码工作正常,如果我通过一个单一id
编辑 我猜,我也试图了解它们之间的区别:
$org->products()->find($ids)->delete()
Run Code Online (Sandbox Code Playgroud)
和 …
我有三个表,分别是User表,Events表和Events_user表.我在Events_user表中有四列是:
Schema::create('events_user', function(Blueprint $table){
$table->increments('id');
$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->integer('events_id')->unsigned()->index();
$table->foreign('events_id')->references('id')->on('events')->onDelete('cascade');
$table->integer('eventstatus')->unsigned()->index();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
我有一个函数,它在用户id上添加一个事件库,显示一个用户可以拥有许多事件.但该事件可以与其他用户共享.功能是这样的:
public function store(EventsRequests $request){
$id = Auth::user()->id;
$events= Events::create($request->all());
$events->user()->attach($id); //Store the User_ID and the Event_ID at the events_user table.
Flash::success('Your event has been created!');
return redirect('/');//Return into home page
// return $events;
}
Run Code Online (Sandbox Code Playgroud)
然后它会帮我更新我的events_user表,但是如何更新eventstatus列呢?任何人都可以告诉我如何更新它?因为我想使用eventstatus帮我确定是否有'1'然后无法编辑,然后编辑按钮将消失.有多少种方法可以实现这个功能?
对于显示页面:我在用户点击日历视图中存在的事件时使用该功能,然后javascript将ID返回并重定向到具有id的视图.
public function show($id){
// $user_id=Auth::user()->name;
$showevents = Events::findOrFail($id);
return view('events.show',compact('showevents','user'));
}
Run Code Online (Sandbox Code Playgroud)
当我想将eventstatus传递给视图时怎么样?所以我可以查看我的视图,如果eventstatus等于1,则编辑按钮不会显示.
更新了关系模型
user.php的
public function events(){
return $this->belongsToMany('App\Events');
}
Run Code Online (Sandbox Code Playgroud)
Events.php
public function user(){
return $this->belongsToMany('App\User')->withPivot('eventstatus');
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用流明开发一个休息api.对于身份验证我使用的是Dingo和JWTAuth api,但是我收到以下消息:
未定义Auth防护驱动程序[api].
下面是Postman的消息截图,包括stacktrace.
laravel ×8
php ×8
laravel-5 ×5
eloquent ×3
lumen ×2
artisan ×1
composer-php ×1
dingo-api ×1
git ×1
jwt ×1
laravel-5.1 ×1
laravel-5.2 ×1
laravel-5.6 ×1
laravel-8 ×1
lumen-5.2 ×1
mysql ×1