i use open sever and when i use jquery, displays error 500 (Internal Server Error). How to fix it? - laravel

i want to sent data in controller laravel, using jquery and ajax. But when i click on button, displays this error
here is my code ajax
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function ()
{
$("#b").bind("click",function ()
{
var id = "888";
$.ajax({
url:"/insert_",
mehtod:"get",
data:{
id:id
}
});
});
});
here is my html code
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<meta name="csrf-token" content="{{ csrf_token() }}">
<script src="js/jquery.js"></script>
<script src="js/f.js"></script>
</head>
<body>
<button id="b">do it</button>
</body>
</html>
here is my controller code
public function data(Request $request)
{
$student = $request->input('id');
DB::table("student_table")
->where("name","=",$student)->delete();
}
here is my web.php code
Route::get('/insert_',"StudentController#data");

I think that the query in the controller is wrong because you are passing the id but then you are using it to retrieve the student's name...
In my opinion, you should change this code
...
$student = $request->input('id');
DB::table("student_table")
->where("name","=",$student)->delete();
...
to
...
$student = $request->input('id');
DB::table("student_table")
->where("id","=",$student)->delete();
...
The problem is that if the student is not found then is not possible to call the delete method. I hope that this answer could help.

Related

How to use laravel-vue-i18n to change translations in laravel blades also?

Can anyone help me make translations working in laravel blades too?
I need to change/translate the contents of the title and description meta depending on the language being switched.
This is how the language changes in Vue:
<template>
<ul class='language-switcher'>
<li :class="{'active': language === 'de'}">
De
</li>
<li :class="{'active': language === 'en'}">
En
</li>
</ul>
</template>
<script>
import {loadLanguageAsync} from "laravel-vue-i18n";
export default {
name: "LanguageSwitcherComponent",
data() {
return {
language: 'en',
};
},
methods: {
switchLanguageTo(lang) {
// ...
loadLanguageAsync(lang);
// ...
},
},
}
</script>
In Vue, the translations work fine, but I need to translate title and description meta in index.balde.php as well.
<!DOCTYPE html>
<html lang="{{str_replace('_', '-', app()->getLocale())}}">
<head>
<title>{{ __("Site Title") }}</title>
<meta name="description" content="{{ __("Site Info") }}">
<meta charset="utf-8">
<meta name="csrf-token" content="{{ csrf_token() }}"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="{{mix('css/app.css')}}">
</head>
<body>
<div id="app">
<index-component/>
</div>
<script src="{{mix('js/app.js')}}"></script>
</body>
</html>
Also, this is how configured i18n in app.js:
import {i18nVue} from 'laravel-vue-i18n';
// ...
app.use(i18nVue, {
lang: 'en',
resolve: lang => import(`../../lang/${lang}.json`),
});
Thanks!
Save site language in cookies and in web.php set locale from cookies.
Route::get('/{any}', function (Request $request) {
// Set locale
App::setLocale($request->cookie('site_language') ?: 'en');
return view('index');
})->where('any', '.*');
Note: Maybe will need to add cookie name in app/Http/Middleware/EncryptCookies.php in $except list to get cookie from the $request successfully.

ng-admin doesn't initialize in another ui-view

I have faced a problem that ng-admin is not rendering inside simple ui-view.
Here is the code:
$stateProvider
.state('home', {
url: '/',
template: homeTemplate
})
.state('login', {
url: "/login",
template: loginTemplate,
controller: 'LoginController',
controllerAs: 'vm'
})
.state('register', {
url: "/register",
template: "<div>Register is under maintenance</div>",
})
;
And here is Html:
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Admin-tool</title>
<meta name="google" value="notranslate">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="shortcut icon" href="favicon.ico" />-->
</head>
<body ng-strict-di class="main-content">
<div id="content-body" class="content">
<div ui-view=""></div>
</div>
<pg-footer></pg-footer>
</body>
Also there is an info message
WARNING: Tried to load angular more than once.
Maybe this is the case? Could you please point me out why it doesn't even render ng-admin simple page?
In browser it just looks like:
<!-- uiView: -->
<div ui-view="" class="ng-scope"></div>
Well, ng-admin has it's own routing so it was needed to make login rout and default on which ng-admin initialize. If it's needed to make custom pages inside ng-admin you just need to specify that in your state like this: parent: 'ng-admin'

Is there an issue retriving json data when using vue, axios, and laravel?

I am trying to replicate a tutorial on vuecasts (https://laracasts.com/series/learn-vue-2-step-by-step/episodes/18).
Everything looks fine and I don't get any errors except a warning:
Resource interpreted as Document but transferred with MIME type
application/json: "http://vueme.app:8000/skills"
I already tried to change content-type to text/html as suggested here:
Resource interpreted as Document but transferred with MIME type application/json warning in Chrome Developer Tools
web.php:
Route::get('/', function () {
return view('welcome');
});
Route::get('skills', function(){
return ['javascript', 'php', 'python'];
});
welcome.blade.php:
<!doctype html>
<html lang="{{ app()->getLocale() }}">
<head>
<meta charset="utf-8">
<title>Laravel</title>
</head>
<body>
<div id="root">
<ul>
<li v-for="skill in skills" v-text="skill"></li>
</ul>
</div>
<script scr="https://unpkg.com/axios/dist/axios.min.js"></script>
<script scr="https://unpkg.com/vue"></script>
<script scr="/js/app.js"></script>
</body>
</html>
app.js:
new Vue({
el: '#root',
data:{
skills:[]
},
mounted(){
axios.get('/skills').then(response => this.skills = response.data);
}
});
What's not working?

Ionic App not able to submit get Request

I have been struggling to submit a simple get request to google places api
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx
I keep on getting an error:
XMLHttpRequest cannot load https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8…ius=500&types=food&name=cruise&key=xxxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '8100' is therefore not allowed access.
I looked this up online and it has something to do with CORS but I havent been able to figure anything out. If someone could point me in the right direction that would be great.
thanks
I was able to call that url restfully using ionic.
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link href="components/lib/ionic/css/ionic.css" rel="stylesheet" />
<script src="components/lib/ionic/js/ionic.bundle.js"></script>
<script src="components/lib/ionic/js/angular/angular-resource.js"></script>
<script type="text/javascript">
angular.module('myApp',
[
'ionic',
'ngResource'
])
.factory('GetData', function ($resource)
{
return {
getg: function ()
{
return $resource('https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=cruise&key=xxxx', null).get();
}
}
})
.controller('SomeController', function (GetData)
{
GetData.getg().$promise.then(
function (answer)
{
console.log(answer);
});
});
</script>
</head>
<body ng-app="myApp" ng-controller="SomeController"></body>
</html>
What worked for me was to install this addon:
cordova-plugin-whitelist
Console:
cordova plugin add cordova-plugin-whitelist

CodeIgniter Check if image existing with Jquery Ajax

I would like check the image whether existing on server file system and the file list was store into database. I want to make a ajax call to doing validation then return the result to screen with append effect. Here is my code, but don't work :( Please help me.
UPDATE: Code is workable, but it's not my expectation, because three thousand record with caused timeout and No append effect. thanks
Controller
public function getImageList()
{
$this->load->model('image_model');
$data['list'] = $this->image_model->get_image();
foreach ($data['list'] as $key){
$result[] = $this->imageValidation($key->filename);
}
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($result));
}
private function imageValidation($imgfile)
{
if(!file_exists(LOCAL_IMG_TEMP.$imgfile))
{
return "<pre>". $imgfile." Not Find"."</pre>";
}
}
View
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<title></title>
</head>
<body>
<script>
function makeAjaxCall(){
$.ajax({
type: "POST",
url: "http://127.0.0.1:8888/index.php/ajax/getImageList",
cache: false,
dataType : "json",
success: function(data){
$("p").append(data);
}
});
}
</script>
</script>
<input type='button' id='PostBtn' value='Check Image' onclick='javascript:makeAjaxCall();' />
<p></p>
</body>
</html>
try to use file_exists()
check it

Resources