在空多重删除上调用成员函数 delete()



我做了一个删除多个函数,但我有一些麻烦。当我选择 2 个复选框并提交它时,但之后我被重定向到url/article/delete/559,并在dd($article_id)处显示null消息。

这是我的控制器功能:

public function deleteArticles (requ $request){
$article_id = $request['news_id'];
dd($article_id);
DB::table('contacts')
->whereIn('id', $article_id)
->delete();
return back();
}
public function delete($id)
{
$careerSolution = AppContact::find($id);
$careerSolution->delete();

return redirect(URL::previous());
}

这是我的路线

Route::get('article/delete/{id?}', 'ContactController@delete');
Route::post('noticeboard/{page?}', array('as' => 'noticeboard', 'uses' => 'ContactController@deleteArticles'));

这是我的观点

<div id="my_contacts_grid" class="profile-edit tab-pane fade in active" style="background: none repeat scroll 0 0;">

<dl class="dl-horizontal">


<?php $count_user = 0; ?>
@foreach($users as $user)
@if($count_user == 0)
<div class="row margin-bottom-20">
@endif

<?php $count_user++; ?>
<form method="POST" action="{{ action ('ContactController@deleteArticles')}}">
{{csrf_field()}}
<div class="col-sm-6 sm-margin-bottom-20">
<div class="profile-blog" style="padding: 0px">
<img class=" noticeboard-profile-picture" src="{{ asset('thumbnail') }}/{{ $user->profile_picture }}" alt="" style="margin-left: 20px;margin-top: 15px;">
<div style="top: 35px;position: relative;right: 85px;margin-bottom:30px" class="name-location">
<ul class="list-unstyled col-xs-12" >
<li>
<strong style="display: inline-table !important">
<h3>@if($user->role[0]->slug == "individuals")
<i style="font-size: 13px;left: 60px;position: relative;top: 2px;" class="icon-user"></i>
@elseif($user->role[0]->slug =='organizations')
<i style="font-size: 13px;left: 60px;position: relative;top: 2px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
@endif<a style="font-size: 16px;left: 60px;position: relative;top: 2px" href="{{ url('') }}/{{ $user->username }}"> {{ $user->username }}</a></h3></strong>
<p style="right: 10px;position: relative;width: 110%">
<i style="padding: 5px" class="icon-real-estate-020 u-line-icon-pro"></i><strong style="display: inline-table !important;font-size: 13px">Location : </strong> {{ $user->country->country }} <span class="{{$user->country->flag}}"></span><br>
<i style="padding: 5px" class="icon-notebook fa-"></i><strong style="display: inline-table !important;font-size: 13px">Industry : </strong> {{ $user->industry->industry }}<br>
@if($user->role[0]->slug == "individuals")
@foreach($user->career_path as $career_path)
<i style="padding: 5px" class="icon-speedometer"></i><strong style="display: inline-table !important;font-size: 13px">Function : </strong> {{ $career_path->functions->function }}
@break;
@endforeach
@elseif($user->role[0]->slug =='organizations')
<i style="padding: 5px" class="icon-frame fa-"></i><strong style="display: inline-table !important;font-size: 13px">Organization : </strong> {{ $user->organization_type->organization_type }}<br>
@endif
</p>
</li>
</ul>
</div>

<hr>
<ul class="social-icons social-icons-color" style="display:none;">
<div class="social-cu" id="social-cu">
<li class="facebook_share" link="{{ url('') }}/{{ $user->username }}" style="left: 5px;position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/facebook-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="twitter_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 15px; position: relative">
<img id="social-im" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/twitter-test.png') }}" alt="" style="height: 22px !important">
</li>
<li class="whatapp_share" link="{{ url('') }}/{{ $user->username }}" name="{{ $user->username }} Workstickers Profile" style="left: 25px;position: relative">
<a href="whatsapp://send?text={{ url('') }}/{{ $user->username }}" style="top: 5px; position: relative">
<img id="social-w" class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" style="height: 25px !important" alt="">
</a>
</li>
</div>
</ul>
<ul class="list-inline share-list" style="text-align: center;padding-bottom:10px">
<li>
<input name="news_id[]" type="checkbox"   class="checkbox_news"  value="{{$user->id}}"/>
</li>
<li>
<a href="{{ url('invitations-reject').'/'.$user->id }}"><i class="fa fa-times"></i> Remove</a>
</li>
<li class="send-contact-message "  data-toggle="modal" data-target="#ssend_message_touser_{{ $user->id }}">
<a href="javascript:void(0)"><i class="fa fa-paper-plane"></i>Send message</a>
</li>
<li class="share-link">
<a href="javascript:void(0)"><i class="fa fa-share-alt"></i> Share</a>
</li>
</ul>
{!! Form::close() !!}
</div>
</div>
@if($count_user == 2)
</div>
<?php  $count_user = 0; ?>
@endif
<!-- Modal -->
<div class="modal fade" id="ssend_message_touser_{{ $user->id }}" role="dialog"  style="margin-top:40px;">
<div class="modal-dialog">
<!-- Modal email-->
<div class="modal-content" style="border-radius: 0px;top: 200px">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="mt-5">Send message to {{ $user->username }}</h4>
</div>
<div class="modal-body">
{!! Form::open(['class' => 'form-horizontal sky-form sky-changes-3','url' => 'message-send']) !!}
<div class="form-group" >
<label class="col-lg-2 control-label" style="display: none">To</label>
<div class="col-lg-10">
<input style="display: none" class="form-control" type="email" name="username" value="{{ $user->username }}" readonly>
<input class="form-control" type="hidden" name="contact_user_id" value="{{ $user->id }}">
<input class="form-control" type="hidden" name="url" value="{{ url('') }}/{{ $user->username }}">
</div>
</div>
<fieldset>
<section>
<label class="label">Subject</label>
<label class="input">
<i class="icon-append fa fa-tag"></i>
<input type="text" name="subject" id="subject">
</label>
</section>
<section>
<label class="label">Message</label>
<label class="textarea">
<i class="icon-append fa fa-comment"></i>
<textarea rows="4" name="message" id="message" ></textarea>
</label>
</section>
</fieldset>


</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" style="bottom: 2px;position: relative">Close</button>
<button type="submit" class="btn-u btn-u-primary">Send message</button>
</div>
</div>
{!! Form::close() !!}
</div>
</div>
<!-- end email Modal -->
@endforeach
<a href="{{ url('article/delete/'.$user->id) }}" role="button" class="btn btn-xs btn-danger" onclick="return confirm('Are you sure you want to delete this article?');">
<i class="fa fa-trash"></i>
</a>
</form>
{!! $users->render() !!}
</dl>
</div>
<style>
#social-cu{
width: 120px !important;
left: 200px;
top: -25px !important;
}
#social-im{
float: left;
width: 22px;
margin-right: 0px;
}
#social-w{
float: left;
width: 25px;
margin-right: 0px;
position: relative;
bottom: 3px;
}
</style>
<script type="text/javascript">
jQuery(document).ready(function() {
App.initScrollBar();
RegForm.initRegForm();
Datepicker.initDatepicker();
CheckoutForm.initCheckoutForm();
StyleSwitcher.initStyleSwitcher();

$(".send-contact-message").live('click', function(){
var user_id = $(this).attr('data-user-id');
$('#ssend_message_touser_'+user_id).modal('show');
});

});
</script>
<script type="text/javascript">
jQuery(document).ready(function() {
// StyleSwitcher.initStyleSwitcher();
$("#select_all").click(function () {
$(".checkbox_news").prop('checked',true);
});
$("#deselect_all").click(function () {
$(".checkbox_news").prop('checked',false);
});

});
</script>

因此,当我选中一个或多个复选框时,我应该能够进行多次删除。

$careerSolution = AppContact::find($id);

当它返回空时,你会得到错误Call to a member function delete()

使用这个:

AppContact::where('id', $id)->delete();

最新更新