Hello,
I wonder why I keep failing saving data. I keep getting this message:
"please fill the title and content article" - eventhough I already fill them in.
article.blade.php
<div class="backend-form create-article-form" style="display:none;">
<div class="form-top">
<div class="form-left">
<h4>Create Article</h4>
</div>
<div class="form-right">
<a href="#" class="btn-save-article setting_save"></a>
<a href="#" class="btn-cancel-article setting_cancel"></a>
</div>
</div>
<div class="form-body">
<div class="form-group">
<span>Tittle</span><input type="text" name="tittle" id="tittle" class="tittle" required/>
</div>
<div class="form-group">
<span>Content</span>
</div>
<textarea rows="10" maxlength="1000" id="content" class="content"></textarea>
</div>
</div>
$(".btn-save-article").click(function(e){
e.preventDefault();
var tittle = $("#tittle").val(),
content = $("#content").val();
$.ajax({
method: "POST",
url: '{{action("AjaxController@postCreateArticle")}}',
data: { tittle : tittle, content : content },
success: function (response) {
if (response=='"error"') {
pesanErr("please fill the title and content article");
}else{
pesanOk("Article created");
setTimeout(function(){location.reload()},1000);
};
},
})
});
AjaxController.php
public function postCreateArticle(Request $request)
{
$domain = $_SERVER['SERVER_NAME'];
$user = User::where('domain', $domain)->first();
if ($user) {
$domain = $_SERVER['SERVER_NAME'];
$user = User::where('domain', $domain)->first();
$tittle = $request->input("tittle");
$content = $request->input("content");
if (empty($tittle) or empty($content)) {
$message = "error";
} else {
date_default_timezone_set("Asia/Jakarta");
$article = new Timeline;
$article->user_id = $user['id'];
$article->social_id = $user['id'];
$article->tittle = $tittle;
$article->content = $content;
$article->status = "0";
$article->updated_at = ("0000-00-00 00:00:00");
$article->social = "article";
$act = $article->save();
if ($act) {
$message = "success";
} else {
$message = "error";
}
}
echo json_encode($message);
}
}