about Promise,this question below my me confused - promise

here is the code:
Promise.resolve().then(() => {
console.log(0);
return Promise.resolve(4);
}).then((res) => {
console.log(res)
})
Promise.resolve().then(() => {
console.log(1);
}).then(() => {
console.log(2);
}).then(() => {
console.log(3);
}).then(() => {
console.log(5);
}).then(() => {
console.log(6);
})
to me,I thought the answer would be 0;1;4;2;3;5;6.But the result is not.Why?

Related

Dropzone.js vuejs laravel message: "Undefined index: width"

When I select a file it is uploaded to the public/upload-images folder. In the laravel Controller the validation fails because the params are not included in the request. When I dump and die. This is what I get. As you can see... the params are missing. Below that is the Dropzone setup.
echo '<pre>';
print_r(request()->all());
echo '</pre>';
die();
$data = request()->validate([
'image' => '',
'width' => '',
'height' => '',
'location' => '',
]);
$image = $data['image']->store('user-images', 'public');
$userImage = auth()->user()->images()->create([
'path' => $image,
'width' => $data['width'],
'height' => $data['height'],
'location' => $data['location'],
]);
return new UserImageResource($userImage);
(
[image] => Illuminate\Http\UploadedFile Object
(
[test:Symfony\Component\HttpFoundation\File\UploadedFile:private] =>
[originalName:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 20220406_125155.jpg
[mimeType:Symfony\Component\HttpFoundation\File\UploadedFile:private] => image/jpeg
[error:Symfony\Component\HttpFoundation\File\UploadedFile:private] => 0
[hashName:protected] =>
[pathName:SplFileInfo:private] => /tmp/phpdAwZvd
[fileName:SplFileInfo:private] => phpdAwZvd
)
)
props: [
'imageWidth',
'imageHeight',
'location',
],
data: () => {
return {
dropzone: null,
}
},
mounted() {
this.dropzone = new Dropzone(this.$refs.userImage, this.settings);
},
computed: {
settings() {
return {
paramName: 'image',
url: '/api/user-images',
acceptedFiles: 'image/*',
params: {
'width': this.imageWidth,
'height': this.imageHeight,
'location': this.location,
},
headers: {
'X-CSRF-TOKEN': document.head.querySelector('meta[name=csrf-token]').content,
},
success: (e, res) => {
alert('uploaded!');
},
error: (e, error) => {
console.log(error);
}
};
}
}

i using laravel-websockets and error Cannot read property 'socketId' of undefined

I do not use socket.io but it gives me such an error
app.js:18695 Uncaught TypeError: Cannot read property 'socketId' of undefined
I wrote in the details, I updated it, I had an SSL problem before, so I could not connect as https, this problem came out when I was dealing with it.
i this using
laravel-websockets,
pusher,
laravel echo
chat.blade.php
var globalChannelId = 0;
var user_id = document.getElementById('user_id').value;
function channel(elem) {
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: '{{ route('channelControl') }}',
cache: false,
dataType: "json",
data: {user_id: user_id, receiver_id: elem.id},
method: 'POST',
success: function (data) {
if (data.status === 200) {
globalChannelId = data.data;
document.getElementById('channel_token').value = data.data;
document.getElementById('receiver_id').value = data.receiver_id;
var message = data.message;
console.log("message")
console.log(message)
var parentDiv = document.getElementById('parentDiv');
parentDiv.innerHTML = "";
var i;
for (i = 0; i < message.length; i++) {
var div = document.createElement('div');
div.classList = "d-flex";
var h6 = document.createElement('h6');
h6.innerHTML = message[i]["user"]["name"];
var span = document.createElement('span');
span.innerHTML = message[i]["message"];
div.appendChild(h6);
div.appendChild(span);
parentDiv.appendChild(div);
}
dinle()
scroll()
} else {
}
}
});
}
var dongu;
function dinle() {
Echo.disconnect();
Echo.connect();
// Echo.leave('privatechat.5D707F5F-CAAF-A775-1FE5-E1EA94208A22');
console.log(globalChannelId);
Echo.join('privatechat.' + globalChannelId)
.here((user) => {
var activeUser = document.getElementById('activeUser');
activeUser.innerHTML = "";
console.log(user);
console.log("here");
for(var i=0 ; i<user.length ; i++){
var h6 = document.createElement('h6');
h6.innerHTML = user[i].name;
h6.id=user[i].id;
activeUser.appendChild(h6);
}
})
.joining((user) => {
console.log('joining')
var activeUser = document.getElementById('activeUser');
var h6 = document.createElement('h6');
h6.innerHTML = user.name;
h6.id=user.id;
activeUser.appendChild(h6);
})
.leaving((user) => {
console.log('Leaving');
document.getElementById(user.id).innerHTML = "";
console.log(user);
})
.listen('PrivateChannelSend', (e) => {
console.log(e.message.message)
console.log(e)
var parentDiv = document.getElementById('parentDiv');
var div = document.createElement('div');
div.classList = "d-flex";
var h6 = document.createElement('h6');
h6.innerHTML = e.message["user"]["name"];
var span = document.createElement('span');
span.innerHTML = e.message["message"];
div.appendChild(h6);
div.appendChild(span);
parentDiv.appendChild(div);
scroll()
})
.listenForWhisper('typing',response => {
console.log('typing');
document.getElementById('yaziyor').style.display = "block";
console.log(response);
if(response){
clearTimeout(dongu);
}
dongu = setTimeout(function(){
document.getElementById('yaziyor').style.display = "none";
}, 3000);
});
}
broadcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'useTLS' => true,
'encrypted' => true,
'scheme' => 'https',
'debug' => true,
'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
]
],
],
websockets.php
'ssl' => [
'apps' => [
[
'id' => env('PUSHER_APP_ID'),
'name' => env('APP_NAME'),
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'enable_client_messages' => true,
'enable_statistics' => true,
'encrypted' => true,
],
],
'local_cert' => '/usr/local/psa/var/modules/letsencrypt/etc/live/sub.xsite.com.tr/fullchain.pem',
'local_pk' => '/usr/local/psa/var/modules/letsencrypt/etc/live/sub.xsite.com.tr/privkey.pem',
'passphrase' => null,
'verify_peer' => false,
],

Laravel + Vue The DELETE method is not supported for this route. Supported methods: GET, HEAD

I am creating an table that displays some data. when i make a delete button , i get an error "The DELETE method is not supported for this route. Supported methods: GET, HEAD."
Delete Method on employeelist.vue
deletePost(id)
{ let uri = `api/account/delete/${id}`;
this.axios.delete(uri).then(response => {
this.accounts.splice(this.accounts.indexOf(id), 1);
});
console.log("Deleted account with id ..." +id);
}
Route
{
path: '/admin',
component: () => import("./components/admin/AdminPage.vue")
children:[
{
name: 'admin',
path:'',
component: () => import("./components/admin/Dashboard.vue")
},
{
path:'/admin/employeelist',
component: () => import("./components/admin/employeeList.vue")
},
{
path:'/admin/calendar',
component: () => import("./components/admin/Calendar.vue")
},
{
path:'/admin/cloud',
component: () => import("./components/admin/Cloud.vue")
},
{
path: '/admin/notification',
component: () => import("./components/admin/Notification.vue")
}
]
},
Controller
public function delete($id)
{
$account = \App\User::find($id);
if(!empty($account)){
$account->delete();
$msg = [
'success' => true,
'message' => 'Account deleted successfully!'
];
return response()->json($msg);
} else {
$msg = [
'success' => false,
'message' => 'Account deleted failed!'
];
return response()->json($msg);
}
}
api.php
Route::get('/account','AccountController#index');
Route::post('/account/store', 'AccountController#store');
Route::post('/account/search','AccountController#search');
Route::delete('/account/delete/{id}', 'AccountController#delete');
and it get error as i said "The DELETE method is not supported for this route. Supported methods: GET, HEAD."
But
when i change the vue route like this
{
path: '/admin',
component: () => import("./components/admin/AdminPage.vue")
children:[
{
name: 'admin',
path:'',
component: () => import("./components/admin/Dashboard.vue")
},
{
path:'/admin/calendar',
component: () => import("./components/admin/Calendar.vue")
},
{
path:'/admin/cloud',
component: () => import("./components/admin/Cloud.vue")
},
{
path: '/admin/notification',
component: () => import("./components/admin/Notification.vue")
}
]
},
{
path:'/employeelist',
component: () => import("./components/admin/employeeList.vue")
},
It work succesfully, but i need it on my vue child route. what should i do?

vue js is not a function

this is my error code "this.fetchArticle is not a function"
created(){
this.fetchArticles();
},
method: {
fetchArticles(){
fetch('api/articles')
.then(res => res.json())
.then(res => {
console.log(res.data)
})
}
}
thank you
Its methods not method
created(){
this.fetchArticles();
},
methods: {
fetchArticles(){
fetch('api/articles')
.then(res => res.json())
.then(res => {
console.log(res.data)
})
}
}

yii2 pjax gridview issue

I am using gridview with pjax in yii2 advanced. When i add/update/delete any record the pjax loads the very first html of page. For example, i have 10 records after deleting a record there should be 9 records, but it still loads 10 records and this continues even if you have deleted all the records. Same goes for add and update as well.
But if i hit F5 then it loads the actual records fetched from the database table and if i do any of the actions again then it again shows 10 records.
Here is the Gridview code with Pjax
$this->registerJs("$('.js-delete').on('click', function(e) {
ajax_actions(this, true, {
'pjax_container': '#products-grid'
});
return false;
});");
Pjax::begin([
"id" => "products-grid",
"enablePushState" => false
]);
echo GridView::widget([
'dataProvider' => $dataProvider,
"summary" => '',
"rowOptions" => function($model) {
if($model->status == Common::STATUS_INACTIVE)
{
return ["class" => "inactive"];
}
},
'columns' => [
[
"class" => 'yii\grid\SerialColumn',
"headerOptions" => [
"class" => 'hidden-480'
],
"contentOptions" => [
"class" => 'hidden-480'
]
], [
"attribute" => "title",
"label" => "Product"
], [
"attribute" => "companies_id",
"label" => "Companies",
"value" => "companies.title"
], [
"attribute" => "product_types_id",
"header" => "Category",
"value" => "productTypes.title"
], [
"attribute" => "part_number",
"header" => "<span class=\"hidden-360\">Part </span>Number"
], [
"attribute" => "created_on",
"label" => "Added On",
"format" => ["date", "php:" . Common::DATETIME_FORMAT_DISPLAY],
"headerOptions" => [
"class" => 'textRight hidden-360'
],
"contentOptions" => [
"class" => 'textRight hidden-360'
]
], [
"class" => 'yii\grid\ActionColumn',
"header" => "Actions",
"headerOptions" => [
"class" => "textRight actions"
],
"contentOptions" => [
"class" => "textRight actions"
],
"template" => "{view} {edit} {delete}",
"buttons" => [
'view' => function($url, $model) {
return Html::a('<i class="' . Common::ICON_VIEW . '"></i> <span class="hidden-640">View</span>', ['view', 'token' => $model->token], ["class" => "call-ajax"]);
},
'edit' => function($url, $model) {
return Html::a('<i class="' . Common::ICON_EDIT . '"></i> <span class="hidden-640">Edit</span>', ['update', 'token' => $model->token], ["class" => "call-ajax"]);
},
'delete' => function($url, $model) {
return Html::a('<i class="' . Common::ICON_DELETE . '"></i> <span class="hidden-640">Delete</span>', ['delete', 'token' => $model->token], [
'class' => 'js-delete'
]);
}
]
]
]
]);
Pjax::end();
functions
function ajax_submit(element, pjax_container)
{
var form = $(element);
if(form.find('.has-error').length) return false;
$.post(form.attr('action'),form.serialize()).done(function(result){
var result = JSON.parse(result);
if(result.type=='error')
{
result.container = '.error-container';
messages(result)
}
else
{
if(pjax_container) $.pjax.reload({container: pjax_container});
$('.overlay').click();
result.container = '.message-container';
messages(result);
}
});
return false;
}
function ajax_actions(element, ask_me, params)
{
if(ask_me == true && ask() == false)
{
return false;
}
var $this = $(element);
var $params = {
callBacks: {
beforeSendAfter: function() {},
completeAfter: function() {}
}
};
if(params != undefined) $.extend(true, $params, params);
$.ajax({
type: 'POST',
url: $this.attr("href"),
cache: false,
beforeSend: function() {
if($params.callBacks.beforeSendAfter != undefined && $.isFunction($params.callBacks.beforeSendAfter)) $params.callBacks.beforeSendAfter();
},
success: function(response) {},
complete: function(response) {
var result = $.parseJSON(JSON.parse(response.responseText));
if(result.type=='error')
{
result.container = '.error-container';
messages(result)
}
else
{
result.container = '.message-container';
$('.overlay').click();
$.pjax.reload({container: $params.pjax_container});
messages(result);
}
if($params.callBacks.completeAfter != undefined && $.isFunction($params.callBacks.completeAfter)) $params.callBacks.completeAfter();
}
})
return false;
}

Resources