我在学习如何在laravel中制作一个ajax帖子时遇到了很多麻烦.我希望能够在验证后使用jquery显示错误但我不知道如何访问发送到我的控制器的对象; 所以我甚至不知道控制器中的"返回"是什么.有人可以带我走过这个吗?
这是我观点的一部分
<meta name="_token" content="{{ csrf_token() }}" />
<div class='row'>
{!! Form::open(['url'=>'register','id'=>'sign-up','class'=>'col-md-6 col-md-push-4 form-horizontal'])!!}
<div class='form-group'>
{!! Form::label('first_name', 'First Name:',['class'=>'col-xs-12 col-md-3']) !!}
<div class= 'col-xs-12 col-md-6'>
{!! Form::text('first_name', null, ['class' => 'form-control'])!!}
</div>
</div>
<div class='form-group'>
{!! Form::label('last_name', 'Last Name:',['class'=>'col-xs-12 col-md-3']) !!}
<div class= 'col-xs-12 col-md-6'>
{!! Form::text('last_name', null, ['class' => 'form-control'])!!}
</div>
</div>
<div class='form-group'>
{!! Form::label('email', 'Email Address:',['class'=>'col-xs-12 col-md-3']) !!}
<div class= 'col-xs-12 col-md-6 '>
{!! Form::text('email', null, ['class' => 'form-control'])!!}
<div class='form-group'>
{!! Form::label('password', 'Password:',['class'=>'col-xs-12 col-md-3']) …Run Code Online (Sandbox Code Playgroud) 只想首先说我不知道我在做什么......我有一个看起来像这样的user_info表
Schema::create('user_info', function(Blueprint $table){
$table->increments('id');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');
$table->string('address');
$table->string('city');
$table->string('state');
$table->string('zip');
$table->text('description');
$table->text('experience');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
我在创建现在看起来像这样的更新控制器时遇到了问题.
public function update(Request $request)
{
$user = $request->user();
$data['description'] = $request->input('description');
$data['experience']=$request->input('experience');
$user->user_info -> $data->save();
}
Run Code Online (Sandbox Code Playgroud)
再一次......不知道我在做什么......
这是我的形式:
<div class='col-md-10 well form-well'>
{!! Form::open(['method' => 'PATCH', 'action'=> ['UserController@update', Request::user()->id]]) !!}
<div class='row'>
<div class='form-group'>
<div class='col-md-2'>
{!! Form::label('description', 'About You')!!}
</div>
<div class='col-md-7'>
{!! Form::textarea('description', null, ['class'=>'form-control', 'rows'=>'3'])!!}
</div>
</div>
</div>
<div class='row'>
<div class='form-group'>
<div class='col-md-2'>
{!! Form::label('experience', 'Experience and Skills')!!}
</div>
<div …Run Code Online (Sandbox Code Playgroud) 当我尝试使用google或fb登录时,我只在本地计算机上出现此错误.我几乎100%确定我的服务和session.php设置正确.但是,唉,我们在这......
我的services.php谷歌设置:
'google' =>[
'client_id'=> env('GOOGLE_CLIENT_ID'),
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
'redirect' => "http://". env('DOMAIN'). "/login/google/callback",
],
Run Code Online (Sandbox Code Playgroud)
我的会议
'domain'=> 'local.mysite.com'
Run Code Online (Sandbox Code Playgroud) 我运行了brew install nginx,当运行'nginx'时我得到了这个消息
nginx: [emerg] open() "/usr/local/Cellar/nginx/1.8.0/logs/proxy.access.log" failed (2: No such file or directory)
Run Code Online (Sandbox Code Playgroud)
查看 /usr/local 我发现 '/etc/nginx' 和 '/Cellar/nginx' 中存在 nginx 文件夹。
我该怎么办?
我将图像保存到 s3 并将 s3 路径保存到我的数据库。当我需要显示图像时,我正在调用路径。所以现在我在将其保存到 s3 之前无法调整该图像的大小。我收到此错误消息:
Command (getRealPath) is not available for driver (Gd).
Run Code Online (Sandbox Code Playgroud)
这就是我的控制器的样子
public function up(Request $request) {
$user = $request->user();
$image= $request->file('images');
if(!empty(($image))){
$files = Input::file('images');
foreach($files as $file) {
if(!empty($file)){
$ext = $file->getClientOriginalExtension();
$media = ($user->media->where('category','profile')->first());
if($media == null){
$media = new Media();
$media->category='profile';
}
$this->saveMedia($media, $user,$file);
}
}
return Redirect::back()->with('message','Your profile has been updated');
}
}
private function saveMedia($media, $user, $file){
$ext = $file->getClientOriginalExtension();
$key = strtotime('now') . '.' . $ext;
$id = $user->id; …Run Code Online (Sandbox Code Playgroud) 我无法弄清楚.我认为它发生在我的activateAccount控制器功能上.在该函数内部,我调用account_activated函数来保存用户.另外,我正在获取用户对象的第一个实例,所以我没有错.
这是控制器功能
public function activateAccount(Request $request, User $user, $key) {
$registered = $request->session()->get('registered');
if (isset($registered)) {
$request->session()->forget('registered');
if ($user->account_activated($key)) {
// TODO
$referral = Referrals::where('activation_key', $key);
if (!empty($referral)) {
$referral->validate = 1;
$referral->save();
}
return redirect('/login')->with('success', "Your account has been activated. You many login!");
} else {
return redirect('/not-active');
}
} else {
return redirect('/');
}
}
account_activated function inside the User model
public function account_activated($key){
$user = User::where('activate_key', $key)->first();
$user->activate = 1;
$user->save();
return true;
}
Run Code Online (Sandbox Code Playgroud)
这是错误消息
BadMethodCallException in …Run Code Online (Sandbox Code Playgroud)