我试图让更新在我的项目中运行,用户点击链接并将它们带到该页面(我有那部分工作),他们可以在那里进行更改。我创建的那一刻并更新功能,但用户点击按钮时没有任何反应。
这是我的home.blade.php,用户点击该链接将其带到另一个页面:
@extends('layouts.app')
@section('content')
<head>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
</head>
<div class="container">
<div class="row">
{{--Friend request--}}
<div class="col-md-8 col-md-offset-2">
@if ($available_req_count > 0)
<div class="alert alert-danger alert-dismissable">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<strong>Your have pending friend request
<a href="{{ url('friends/viewReq') }}" class="alert-link">Please check</a>
</strong>.
</div>
@endif
</div>
<div class="col-md-8 col-md-offset-2">
{!! Form::open(['url' => 'home','files' =>true]) !!}
<div class="panel panel-default">
<div class="panel-heading">Add a new status</div>
<div class="panel-body">
<div class="form-group">
<label>Write a new status</label>
<textarea class="form-control" name="status-text" id="status-text"></textarea>
</div>
</div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-md-6">
<div id="image_upload">
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-image"></i> or <i class="fa fa-video-camera"></i>
</label>
<input id="file-upload" name="status_image_upload" type="file"/>
</div>
</div>
<div class="col-md-9=">
<button class="btn btn-info pull-right btn-sm"><i class="fa fa-plus"></i>Add status
</button>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
@foreach($top_15_posts as $status)
{!!
view('layouts.app-internal.user-status-layout',[
'status' => $status,
'user' => \App\Eloquent\User::find($status->user_id),
'comments' => \App\Eloquent\StatusComments::where('status_id',$status->id)->orderBy('id','DESC')->get(),
'comment_count' => \App\Eloquent\StatusComments::where('status_id',$status->id)->count(),
'like_count' => \App\Eloquent\StatusLikes::where('status_id',$status->id)->count()
])
!!}
@endforeach
</div>
</div>
</div>
@endsection
此edit.blade.php将用户从主页带到:
@extends('layouts.app')
@section('content')
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Edit a status</div>
<div class="panel-body">
<div class="form-group" action="{{url('edit')}}/{{$status->id}}" method="POST" role="form">
<label>Write a new status</label>
{!! Form::open(['url' => 'home','files' =>true]) !!}
<textarea class="form-control" name="status-text" id="status-text" value="{{ $status->id }}"></textarea>
</div>
</div>
<div class="panel-footer clearfix">
<div class="row">
<div class="col-md-6">
<div id="image_upload">
<label for="file-upload" class="custom-file-upload">
<i class="fa fa-image"></i> or <i class="fa fa-video-camera"></i>
</label>
<input id="file-upload" name="status_image_upload" type="file"/>
</div>
</div>
<div class="col-md-9=">
<button class="btn btn-info pull-right btn-sm"><i class="fa fa-plus"></i>Add status
</button>
</div>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
@endsection
这是控制器:
<?php
namespace App\Http\Controllers;
use App\Eloquent\Status;
use App\Friends;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Laracasts\Flash\Flash;
//use Request;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\DB;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
if (Input::has('like_status')) {
$status = Input::get('like_status');
$selectedStatus = Status::find($status);
$selectedStatus->likes()->create([
'user_id' => Auth::user()->id,
'status_id' => $status
]);
return redirect(route('home'));
}
if (Input::has('post_comment')) {
$status = Input::get('post_comment');
$commentBox = Input::get('comment-text');
$selectedStatus = Status::find($status);
$selectedStatus->comments()->create([
'comment_text' => $commentBox,
'user_id' => Auth::user()->id,
'status_id' => $status
]);
Flash::message('Your comment has been posted');
return redirect(route('home'));
}
if (Input::has('status-text')) {
$text = e(Input::get('status-text'));
$rules = [
'status-text' => 'required|string',
];
$vaildator = Validator::make($request->all(), $rules);
if (Input::hasFile('status_image_upload')) {
$file = Input::file('status_image_upload');
$mime = $file->getMimeType();
$image = $request->file('status_image_upload');
$imageName = str_random(8) . '_' . $image->getClientOriginalName();
//$imageFull = str_random(8).'_'.$image->getClientOriginalExtension();
$userStatus = new Status();
$userStatus->status_text = $text;
$userStatus->image_url = $imageName;
$userStatus->type = 1;
$userStatus->user_id = Auth::user()->id;
if ($mime == "video/x-flv" || $mime == "video/mp4" || $mime == "application/x-mpegURL" || $mime == "video/MP2T" || $mime == "video/3gpp" || $mime == "video/quicktime" || $mime == "video/x-msvideo" || $mime == "video/x-ms-wmv") {//process upload}
$vaildator = Validator::make($request->all(), $rules);
if (!$vaildator->fails()) {
$image->move('status_videos', $imageName);
$userStatus->type = 2;
$userStatus->save();
Flash::success('Your status has been posted');
return redirect(route('home'));
} else {
return back()->with('error', 'Validation failed:' . $vaildator->errors);
}
} else {
$rules['status_image_upload'] = 'image';
$vaildator = Validator::make($request->all(), $rules);
if (!$vaildator->fails()) {
$image->move('status_images', $imageName);
$userStatus->type = 1;
$userStatus->save();
Flash::success('Your status has been posted');
return redirect(route('home'));
} else {
return back()->with('error', 'Validation failed:' . $vaildator->errors);
}
}
} else {
}
if (!$vaildator->fails()) {
$userStatus = new Status();
$userStatus->status_text = $text;
$userStatus->user_id = Auth::user()->id;
$userStatus->save();
Flash::success('Your status has been posted');
return redirect(route('home'));
} else {
return back()->with('error', 'Validation failed:' . $vaildator->errors);
}
}
//Get top 15 post
$user_id = Auth::id();
$all_friends = Friends::where(['friend_id' => $user_id, 'status' => 1])
->orWhere(['user_id' => $user_id, 'status' => 1])
->get();
$friends = [];
foreach ($all_friends as $val) {
array_push($friends, $val->user_id, $val->friend_id);
}
$unique_friends = array_unique($friends);
if (!empty($unique_friends)) {
$top_15_posts = Status::whereIn('user_id', $unique_friends)
->orderBy('id', 'DESC')
->take(15)
->get();
} else {
$top_15_posts = Status::where('user_id', $user_id)
->orderBy('id', 'DESC')
->take(15)
->get();
}
//Get available friend request
$user_id = Auth::id();
$available_req_count = Friends::where(['friend_id' => $user_id, 'status' => 0])
->orderBy('id', 'desc')
->get()
->count();
return view('home', [
'top_15_posts' => $top_15_posts,
'available_req_count' => $available_req_count
]);
}
public function getDeleteStatus($status_id)
{
$status =Status::where('id',$status_id)->first();
// if(Auth::id() != $status->user){
// return redirect()->back();
// }
$status->delete();
return redirect()->route('home')->with(['message' => 'Successfully deleted!']);
}
public function edit($id)
{
$status = Status::find($id);
return view('edit',compact('status'));
}
}
答案 0 :(得分:0)
当我点击edit.blade中的按钮时,没有任何事情发生
在您的edit.blade.php和表单中,您确定没有提交按钮
替换:
<button type="submit" class="btn btn-info pull-right btn-sm"><i class="fa fa-plus"></i>Add status
</button>
使用edit.blade.php中的按钮代码
如果您有任何错误,请告诉我