ArtisanTinkerer.github.io

Blog

View on GitHub

5


# 6 

Makes an array:

$thread = factory(‘App\User’)->raw()


# 15 Refactoring

```Threadfilters.php```


# 16

# 20 Queries
Check with Debugbar

# 21
Eager load in model:
```protected $with = ['creator'];```

Can also add global scopes
#22 Profiles


#29 Vue
* flash message in one component

#32 A Vue Reply Component

* vue component to edit reply
* uses an inline template  - works well with Laravel
* v-cloak - autonatically removed when component is loaded

#33 Ajaxing the delete
JQUery fadeout the element when deleted.

$(this.$el).fadeout(300, () =>{

});

#34 A Vue Favourite Component

* Child components
In parent:

import Favourite from ‘./Favourite.vue’

export default {

components: { Favourite }

Can add attributes which get used when converting to JSON

protected $appends = [‘favouritesCount’];


# 35 Squashing Bugs

# 36

Replies collection component
When adding a component to app.js, this makes it a global component.
Alternatively they could just be imported in the components where they are used:

# 66 Redis

## A sorted set

* Push to redis everytime a thread is read
* Array sorted by score

zincrby ‘trensing-threads’ 1 ‘Some thread title’ zincrby ‘trensing-threads’ 1 ‘Another thread title’

// to view zrange ‘trending_threads’ 0 -1 zrevrange ‘trending_threads’ 0 -1 WITHSCORES


Laravel:

Redis::zincrby(‘trending_threads’, 1 , $thread->id);

//or

Redis::zincrby(‘trending_threads’, 1 , json_encode([ ‘title’ => $thread->title ‘path’ => $thread->path() ]));

Redis::zrevrange(‘trending_threads’,0,-1);








# 69 Extract a Class

public function resetVisits public function otherVisits


* refactor to methods on Visits class
* give thread a helper method ``` $thread->visits()```
This just news up a Visit class and returns it.

# 94 First Class Search
## Laravel Scout
Add Searchable trait to model.

scout:import scout:flush

New records get automatically added.

# 95 Searching

Thread::search($search)->paginate(25);


In test set the SCOUT_DRIVER to null


# 101 Sanitizing is a must.

Script in body
This will be escaped:

```

This is not escaped. JS can be executed. {!! $body !!}

Can use strip_tags($body,'<h1>','<h2>') to allow some.

Can use a package and an editor.